I’m having a big problem with Unity, and I’d like to know if somebody has experienced the same or knows what is happening. Basically, I have been noticing since some months ago that at seemingly random times the values of some components in some prefabs just reset to the default values (for example, to 0 for ints and floats).
I’m 100% sure this is happening, in a project I’m working now I had some prefabs with a particular component perfectly initialized, and just a moment ago all its values went to 0. The curious thing is that it happened on all the prefabs with that component, except one which conserved the values. What I’m not sure about is whether it happens only on prefabs, may also happen with other objects in the scene.
This has happened me in two different projects, and I have no idea what triggers it. Obviously, I don’t change the values anywhere in code, the only thing I’ve done this time is modifying the component script, which didn’t have any errors, test in the editor, and then make a build for Android to test. I have no idea in which step it happened. At this point I just feel that I cannot trust Unity and that I have to be checking everything every time I make some change, and it’s driving me completely crazy.
It sounds like you deleted and readded a variable, or renamed it, because thats when thus should happen, but not with every variable. Since unity is quite unstable since 5.0, this can really easily be a bug
That’s what I thought at first, because actually I renamed the variables. However, I used the “FormerlySerializedAs” attribute so that the values weren’t lost, and it worked fine. Also, it wouldn’t leave one of the prefabs with the correct values and wipe the rest. And I think the other times that it’s happened I didn’t change any names (though I’m not 100% sure about that, but anyway I’m always very careful to use “FormerlySerializedAs” in these situations).
The only thing that could be happening in this sense is that Unity stores the old names “somewhere” even after correctly changing them with “FormerlySerializedAs”, and then at some point it tries to restore the serialized data with those wrong names, but I wouldn’t actually bet too much on that.
Holy sheep, I found the issue! I take back what I said, it’s actually a problem when changing variable names, even when using “FormerlySerializedAs”: if you make a build with the old names and then change them and apply “FormerlySerializedAs”, go to the editor so the new names are applied, and go back and remove “FormerlySerializedAs”, everything will work fine in the editor. But as soon as you make a new build the variables will be wiped (except it won’t wipe them in some objects, for unknown reasons). If you don’t remove “FormerlySerializedAs” before making the build, everything will be fine.
I guess the serialization system maintains data separately for the editor and the other platforms, so when you make a build the serialized data for that platform, which doesn’t have the new names, will be used.
I consider this a bug, I’ll prepare a repro project to send to Unity.
So the updated variable names are not automatically changed. You can see this if you use git or some other VC system, and open a scene where you’ve changed variable names in scripts. The yaml-based scene file (whatever.unity) doesn’t update the names of the variables before something else has changed. So until Unity has actually done a change to the object, the variable will be stored with the old name, and the value will be written to the correct field on play.
The lesson from this is: don’t remove FormerlySerializedAs.
So i know this is an old thread, but I really can’t find any solutions to my very similar problem. I modified the standard assets third person control script and changed the gravity modifier variable from a serialized field to public. Ever since, my main character drops like a ton of bricks. I debugged the y velocity and gravity modifier and found that she drops faster in fullscreen mode, even though gravity modifier is unchanged according to debug.Log. When I click on the instance clone in the hierarchy during playmode, everything does what I expect it to, but gets buggy again once I deselect the clone. Have you found a solution? This really sucks.
@belamessex Unity already fixed the issue I had, but anyway your problem seems to be completely unrelated. Did you modify something else in the script apart from setting the variable to public? I’d say the problem is something else.