- Home /
Lifespan of a Delegate with respect to the Container
I am currently working on a shooter, and want to have a common projectile class, and then have each weapon have its own effect. so each WeaponClass that derives from WeaponBase (abstract base class) will override a delegate implementation.
then the Projectile will have an instance of that delegate that will be handed to the receiver, to actually apply the effect.
if ObjectA holds a reference to a delegate defined in a class on ObjectB. what happens when ObjectB is destroyed (released for garbage collection), and in addition what happens if ObjectA handed that same delegate reference to an ObjectC (to run the delegate over a series of loops)
for the final paragraph it can be assumed that ObjectA will also be destroyed as well after the delegate reference is passed.
I don't really get it, what you show is not a delegate but an abstract method, still you talk about it like a delegate.
the abstract method matches the signature of a delegate defined externally which is completely legal.
@gardian06: Hmm, why have you included a line that isn't actually related to the problem, but the actual delegate is not there.
Answer by whydoidoit · Apr 12, 2013 at 03:13 PM
When ObjectB is "Destroyed" will cause ObjectB to start to return null when referenced (thanks to some internal Unity magic), this could well cause your Delegate to fail.
Destroying a game object causes problem in Unity compared to normally losing a reference as you would in C# in a traditional .NET setting (where it would still be reachable and therefore valid).
Your answer
![](https://koobas.hobune.stream/wayback/20220613100201im_/https://answers.unity.com/themes/thub/images/avi.jpg)