#quick question on delegates?
1 messages · Page 1 of 1 (latest)
If its non-static, I assume that "local object" is also in the scene, and would get cleaned up with a scene change, in that case both the listener and delegate would be cleaned up by GC - if the delegate is part of DDOL so it persists scene changes, AFAIK the listener is stored in memory even though its reference is now null, so its always a good idea to unsubscribe if your going to subscribe to something - usually I will subscribe in OnEnable and unsubscribe in OnDisable if I know the thing will be toggled, or subscribe in Awake/Start and unsubscribe in OnDestroy if I know the thing will persist for a unknown lifetime
This post may also be a good read on the topic: https://gamedev.stackexchange.com/questions/204735/is-it-necessary-to-unsubscribe-from-c-events-when-the-event-owner-has-already-b
ok so the delegate is not a DDOL which mean it will get cleaned up with the scene change ok. second what does AFAIK mean?
the reason why I am asking this question is because
one scene I have a local delegate and two characters with different debuffs. when one character is active their debuff will be on the delegate but when the focus change to the other character then their debuff will be on the delegate.
but I want some debuff to stay active when the character is not on focus or is always on
ok I read the link you gave and I know both publisher and subscriber get destoryed when the scene change
thank you for answering my question