Disregard: Changed my search criteria and found the Script Execution Order, problem solved.
Hi, I have lets say 2 scripts, ScriptA and ScriptB. ScriptA at runtime creates a public random int value in the Start() function. ScriptB uses the random value that ScriptA created. But ScriptA is being loaded after ScriptB so it’s always returning a value of 0;
Is there a LateStart() or some other function that will allow scriptA to first load before ScriptB tries to access the value? Or is there some way to make sure scriptA always loads first?
I tested this with the Print() function and scriptB loads before ScriptA
Just as a quick reply, I absolutely abhor the script execution chain route, I prefer to have the scripts trigger each-other in the order that I want them to fire rather than mess about.
Thanks Baste, I was aware of the Awake function and I use an awake() method often in my objective c scripts to set everything up. I did try the awake() before I posted here for help and it didn’t work. It seems like each script is initialized one by one. So scriptA starts with Awake() then loads everything in ScriptA before starting on ScriptB. So if ScriptB needs data from ScriptA, but ScriptB loads before ScriptA it doesn’t work.
If all scripts loaded at the same time, say both ScriptA and ScriptB both loaded the Awake() functions before the Start() functions, then you could set variables and such before all the Start() functions fire in varies scripts.
It works like that. It’s easy to check, just put log statements in both scripts.
Awake will run on every script as soon as they’re loaded. Start will run on the start of the first frame a script exists. The only way script A’s Awake hasn’t run before script B’s Start is if script A didn’t exist when Script B’s Start ran.