- Home /
If an instance of a class containing an event is destroyed, will I need to unsubscribe connected functions from it?
I'm making a shooter and each enemy has a Died event, and I want my game manager to find out when the enemy count is 0 by updating every time one dies. When enemies die, they are destroyed. I'm wondering if I will need to disconnect the update function when this happens.
Answer by madks13 · Jul 04, 2018 at 03:36 PM
For cleanliness purposes, YES. Also, it's the event handler that stores the subscribers, so if you don't there will be a strong link left inside your objects and they will not be collected by the garbage collector. They will then remain in the memory till the application is closed.
Your answer
Follow this Question
Related Questions
Subscribing to Unity Events with different signatures 1 Answer
Generic Triggers and Actions 0 Answers
Navmesh event on navigation end 0 Answers
Question regarding events and event managers. 2 Answers
Play an Animation through a Script 2 Answers