I’m currently doing a bunch of stuff in EditMode with one of my GameObjects. The GameObject works fine (switching between Scene and Game) as long as I DON’T Prefab it and use a Prefab instance. If I do, public variables I modify in C# script are lost when the game is run.
For example if I drag in a Prefab and modify an integer in the Inspector View, let’s say I set it to 10. It remains 10 when I run the game. But if I change that integer from C# script instead (for example in the Update() function), it reverts back to the Prefab default on game start.
Is there a way for instances of Prefabs to preserve their public variable values when I modify those variables in script instead of the inspector?
Hi, i got the same problem.Could you please explain what i should do with Undo.RecordObject?
I have script ScriptA which runs in edditor mode, and this script change value of ScriptB in prefab object
I tried call Undo.RecordObject(ScriptB , “Change description”) in Update in ScriptA and nothing happens