Race condition in CinematicsControlRemover?

In this lecture Sam moves the initialization of GameObject player with GameObject.FindWithTag() to Awake.

I thought that the guideline was that other gameobjects should not be accessed in Awake, and that Awake should be used to deal with internal data only. Have I misunderstood it?

You can (and should) cache references to GameObjects and Components that are part of the scene in Awake. Basically, at this point, you can get the “address” of the player.

You should wait to act on those references until OnEnable() (for subscribing to events) or in Start() or Update()

2 Likes

Oh, good to know, thanks. I thought that objects were not even created before their awake was called.
Thanks!

If you’re used to Unreal, that’s absolutely correct when it comes to OnCreate(). Even in Unity, “exist” is a big word. You can get a reference, you can even get references based on the references, like getting a heatlh component on a player, but don’t act on them. Those references only exist in the Heirarchy… were you to try to access a value on the component, you’ll likely get bad results.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms