in my case, I am Instantiating a number of objects in the Start() function of a ‘Level manager’ script… to be exact, the pieces of a gameboard.
Lets just say there’s a boolean in the Script attached to each gameboard which I want set during the Level Manager Start() funciton.
So for example -
Transform t = (Transform)Instantiate(GamePiecePrefab);
t.GetComponent<GamePiece>().bIsRed = true;
the bool bIsRed will never change to true - it will always stay as it was declared in the class.
So I’m wondering if because I’m instantiating these objects in the LevelManager Start(), the GamePiece script never runs its own Start() and therefore… well, can’t be modified yet? I don’t know!
Are your newly instantiated objects active?
How are you testing for the value becoming true?
Bear in mind, that if you instantiate an object in a Start() function, that the Start() function of the newly instantiated object will not be called until after the currently executing Start() has exited or you have yielded.
Start() functions of objects instantiated will always be called, assuming they are active, but not immediately after instantiation. This caught me out just a few days ago when I had a different thread querying the scene for newly instantiated objects of a particular type.
thanks for the link, good quick read - but I’m not sure it’s realted to what I’m experiencing?
It’s not that the instantiated objects don’t run their Start() code (or that I have an ordering problem yet! ), it’s that I can’t change properties on those objects
Like so…
In the ‘Level Manager’ I tried this
Transform t = (Transform)Instantiate(GamePiecePrefab);
t.GetComponent<GamePiece>().SetIsRed(true);
Then, in the GamePiece I have this function
public void SetIsRed(bool b)
{
bIsRed = b;
print(bIsRed + " was set");
}
so this prints to the log
“True was set”
but in update of GamePiece I then print out bIsRed and it is still false. No where else other than declaration is it set to false.