- Home /
Object instances in code lifetime in comparison with gameobject
So, it comes to this. Maybe newbish question but I dare to ask.
We have GameObject with attached script, which contains derived from Monobehaviour class. When gameobject appears in the scene we have new instance of the C# object (of the attached class) automatically and can access it from code.
The question is when this instance of an C# object (not GAME object) is destroyed?
I have been thinking Unity makes it automatically: gameobject destroyed, C# instance of a class destroyed, no problem bro.
But I was wrong. I have totally deleted gameobject and still working C# instance of the class, which belonged to that GAMEobject. It had some members registered as a callback (delegate) functions upon deletion though.
Maybe there is some logic with active links on that C#object when gameobject is being destroyed and so on? Please, share your knowledge.
Your answer