Understanding the use of the instance property vs referencing a serializefield

Hi, enjoying the course so far but I’m really stuck on this so I must not be understanding properly.

From our Unit we can’t use a SerializedField to reference the event because a prefab can’t reference a scene variable directly and that’s ok.

But isn’t the singleton that we reference just another way of referencing a scene object from within the prefab, which kind of makes this a workaround?

Wouldn’t that code in the prefab fail in another scene that doesn’t include the UnitActionSystem object?

I may have to watch this a third time :slight_smile:

1 Like

For a SerializeField, you have to drag the reference during Edit time, meaning while the game is not playing.
Whereas accessing the static instance, that is fetched during Run time, meaning while the game is playing.

And yes you are right, if there’s no UnitActionSystem when the game is running and the script accesses the instance then you will have a NullReferenceException.

4 Likes

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

Privacy & Terms