M
M
MishkaVNorky2019-02-07 12:36:29
C++ / C#
MishkaVNorky, 2019-02-07 12:36:29

How to competently implement OnDisable and OnDestroy?

To begin with, I have a question, why are there so many stupid people in the unit? What is the logic behind the implementation of OnDisable and OnDestroy??
Let's say I have a GameObject - a store page, I need to include additional onEnable and OnDisable. elements. That is, we logically build a chain, when the object turns on and off, I do additional. processing.
BUT why is it so stupidly done that when OnDestroy works OnDisable ?? It's just insanity.
It turns out that when the scene / object is destroyed, it always handles OnDisable and do calculations there. That is, these are absolutely useless calculations at the time of the destruction of the object.
Why couldn't it be human? You need to disable the object, put the code in OnDisable , you need to destroy the object onDestroy .
Thank God that they were smart enough not to call Awake, Start, OnEnable when destroying )))))
Or am I just stupid, I guess? How do you get around this? It's not about ending the game.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2019-02-07
@GavriKos

How do you get around this?

It is not necessary to simply operate on unit events at the level of game logic.
OnDestroy/OnDisable are needed to operate on the state of the object as an engine entity, but not as a game entity.
If you need to destroy a light bulb, call YOUR Destroy method on it.

N
Nikita Kirakosyan, 2019-02-12
@Noomank

It's like asking: "Why does OnMouseOver work every frame??"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question