How to do it, only execute when the object is destroyed, not when switching scenes or exiting the game .
I want to remove the object from the list when the object is destroyed, but don’t do it when the scene ends because it is not necessary, because the list itself is also destroyed
Because the list itself will also be destroyed, remove is not necessary and wastes performance
Sometimes I want to use OnDestory to play the explosion effect when the unit dies, but I don’t need to do this when I exit the game
You could create an event and subscribe to it at runtime. When the Ondie is needed, call the event. In the event, remove the object from the list and play your effect. Eliminating onDestroy from the equation. Should do what you’re wanting.