Troglodyte In the Underbelly: Race Condition

 Author - Daniel Reder

Unity's start function acts as its name implies; it runs at the start. However, with multiple Gameobjects calling start when the project is run, some start functions have to run before others, and some after others. This can lead to inconsistent behaviors and can create unforeseen problems, as one moment everything runs fine, and the next time you run the program nothing works. An example of this would be if you were to call Getcomponent in the start function. Depending on the order of the objects being created, the component you are trying to reference may or may not exist at the time, and can lead to a nullreference even though the component may actually exist in the scene.


Of the methods used to get around this problem, the version i choose was to use a coroutine and delay it. This works as the method can be delayed to the point where all objects have been initialized. Since all objects and their components have been initialized, this cannot cause a null reference issue, as unless something else has happened, the object is alive in the scene.

Comments

Popular posts from this blog

Troglodyte In Underbelly: Git Issues