- Home /
How to delete object which contains script with inherited class
How to delete object which contains script with inherited class? When I just delete this object and I will call an abstract class event, unity still trying to get into deleted inherited class. (getting error that that script is null) Sorry for my english
can you share the code where the error happens? are you unsubscribing from the event?
Answer by Esteem · Jul 15, 2019 at 11:55 AM
it's not clear to me what you mean by object.
is it object? or object? or maybe object?
I'll suppose you're talking about the third one: if you have a reference to the game object you just call Destroy(referenceToGameObject) or Destroy(yourScript.gameObject) if it is a mono Behaviour
You cannot delete the object that has a MOnoBehaviour inherited class on it and then call an event of that destroyed class. Cannot cook the food you already ate.
what you should do is call the event first and destroy the object second. (you can also destroy the object from its own event)