I have one script called "MyTest". Then, I want to use it but without adding it to any gameobject, just by making a "new" of the script class. Here is the other script "OtherScript.js" : private var mTest : MyTest; function Start() { mTest = new MyTest(); } function Update () { Debug.Log(mTest); /* LOGS "MyTest" */ if (mTest != null) { /* NEVER ENTERS HERE !!! */ Debug.Log("Hello"); } } It seems like in the Update function the "mTest" instance is set to something (If I log it, I get "MyTest" instead of null) but later the comparation is null... What am I missing here?? Thank u!
If MyTest inherits from MonoBehaviour (and since you use js it does by default unless you specify otherwise) the equality operators (and method) are overloaded to return null if the script isn't attached to a gameobject. In case UT passes this way: This is extremly annoying!
grrrrrrrrrrr grrrrrrrrrrrrrrrrrrrrrr Thank you!!! I have resorted to have it attached to the gameobject... but I'll try to overload it again so to override this behaviour
For a three page thread see http://forum.unity3d.com/viewtopic.php?t=6816&highlight= Skip to the later pages for more elaboration on this exact problem and workarounds.