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…
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!