A strange question go.IsActive()
Hi. I came across an error that shows up in Editor mode. If the game is stopped (by pressing the play button), If I code like this
void OnDisable()
{
if (GameObject.Find("Controller"))
{
// my code
}
}
This error occurs. however If I code like this
void OnDestroy()
{
if (GameObject.Find("Controller"))
{
// my code
}
}
This error will not appear.
this GameObject I I did not destroy it.everything seems work ok,is this a really error?
Answer by Nazirzadeh · May 25, 2016 at 05:20 AM
OnDisable() function is called when the object is destroyed. Maybe you are trying to access to a Gameobject which there is not exist.
thank you.
function OnDisable () : void Description:This function is called when the behaviour becomes disabled () or inactive.This is also called when the object is destroyed and can be used for any cleanup code. When scripts are reloaded after compilation has finished, OnDisable will be called, followed by an OnEnable after the script has been loaded.
function OnDestroy () : void Description: This function is called when the $$anonymous$$onoBehaviour will be destroyed.OnDestroy will only be called on game objects that have previously been active.
This is the official description of technical documentation,but I still do not know the difference between the two functions.
Answer by Sergasteam · May 25, 2016 at 06:53 AM
Are you kidding? Why are you updating post every time!?
Your answer
Follow this Question
Related Questions
Using foreach to remove and delete bullet in List - C# 3 Answers
Press an image and destroy it 0 Answers
Destroy prefabs after they have been instantiated (C#) 1 Answer
Player falls through destroy collider 1 Answer
Some coding help needed 1 Answer