Using .js:
In a random script I create a dynamic object (empty GameObject):
var object = new GameObject("Hi");
Attach a component
object.AddComponent("Blah");
Blah.js looks as follows:
class Whatever {
var name : String;
}
var Nifty : Whatever[] = new Whatever[15];
function DoSomething(){
this.Nifty[0].name = "Sparky";
}
function Start(){
this.DoSomething();
}
This causes:
NullReferenceException: Object reference not set to an instance of an object
The error is occurring when I try and access this.Nifty[0]; I can’t change or access any of the variables
Now I change it:
function Update(){
this.DoSomething();
}
The same error occurs. But now, if I click on the dynamically created object (“Hi”) in the Hierarchy, the error stops in the Console AND this.Nifty[0].name is changed to Sparky. So, there isn’t really an error in syntax here.
This bug did not occur when I used non-dynamically created GameObject and simply attached the script to a empty object already in the scene.
What is going on here?
Thank you.