Under review

Local variable values on a prefab are going null on play

Alex Martinelli 2 months ago in Game Creator updated by Marti (Lead Developer) 1 month ago 6

I have a few prefabs holding information in the form of local variables in my game. For some reason, the values of the variables will turn to null when I hit play, then revert back to their original value in edit mode. This has also been affecting instantiated versions of the prefabs. Also, I've noticed that this doesn't happen on the first time I enter play mode per session, only the times following the first. Any help would be great, thanks!

[Edit]: Apologies, I tested it further and it turns out instantiated clones of the prefab preserve the original variable values. Unfortunately, the problem persists when trying to get the values from the prefab directly.

Unity version:
Game Creator version:
Under review

Could it be that these prefabs with Local Variables have the "save" checkbox enabled? Try disabling it, and it should preserve the value.

Prefabs shouldn't use the save/load system eitherway.

Also it seems to happen at random. Sometimes it does stay. 

Im having this issue as well. Im using 2019 LTS. Variables wont stay in prefabs. The globa variables are not checked for saving either. 

See video link. Im entering and exiting prefab. Also happens when I enter and exit playmode. 


Not a bug

You can't access a variable from a prefab and expect the value to be the scene object. These are two different objects. Imagine if you created two scene objects from the same prefab. Which value should return when accessing the prefab's variable? The first instance or the second one? Instead, you need to store the scene instance and access the variable from that.

Andi I'm creating a separate thread for this, seems like a different issue.

is it still a scene object when its on a prefab. And the camera motor im trying to access its set into a global variable. I Don't understand what i need to do. Make it a local variable and set it in every scene? I dont see how that works.