+3
Fixed

Local variable values on a prefab are going null on play

Alex Martinelli 5 months ago in Game Creator updated 4 weeks ago 8

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:
2019.3.7f1
Game Creator version:
1.1.8

Answer

Answer
Fixed

This issue has been addressed and will be fixed in the next version. We've split the Change Camera action into two: One for changing to a new camera motor using a scene motor and another one from a Global/List/Local variable.

No breaking changes are expected. Cheers!

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. 

https://gyazo.com/f13e71345c19db0f99d81f8113d77263

+1
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. 

Answer
Fixed

This issue has been addressed and will be fixed in the next version. We've split the Change Camera action into two: One for changing to a new camera motor using a scene motor and another one from a Global/List/Local variable.

No breaking changes are expected. Cheers!

Thanks so much! I'd also like to note that I've been able to fix it by instantiating the prefab instead of trying to access the local variables directly. It's a bit more work, but it has its own advantages as well.