- Home /
My public variables are gone after opening Unity the next day.
Hello, so my problem is that I have opened Unity the next day, but when I see the public variables on my scripts, they are now empty. How can I fix this, or how can I see a file that enables me to make sure all this information is being stored safely. Thanks.
Answer by eladiozro · Nov 05, 2018 at 07:24 PM
Thanks, yeah, you're right, by the way the information was restored after refreshing a little the GameObjects ( I think it was the scene what was reloaded ), so the information was there, but it wasn't being able to access it.
Answer by AaronXRDev · Nov 05, 2018 at 05:31 PM
This is pretty uncommon but can happen if the GameObject or script gets removed and re-added or duplicated (the duplicate will be empty but the original should be intact).
Usually the best way to prevent this is to use some sort of source control like Git or Unity's own Collab feature. That way you can revert to a previous good state and work from there if you need to.
Yeah the thing is that just turned off the PC and the next day this this happened, but Is there any file that stores this information so I can make sure it's safe.
Answer by swanijam · Nov 05, 2018 at 05:50 PM
Are you sure that these are the same instances of the scripts in the same scene from yesterday, and that you remembered to save your scene changes after working yesterday? The public variables plugged into any component are saved in the scene file, and only for each specific instance of the script. If your scene file was not saved, or was corrupted, or if these are new instances of these scripts, or if you only set those values in play mode, these components would have null values in their public fields.
It might be because of some errors in the script, and because of maintaining those errors the next day it was null. So isn't there any way to maintain the public variables info 100% safe, like in a very long string that can't be modified, or something?
I don't think unity would be able save any info about the component if the component failed to compile. It would retain all the data from the last version of the component instance that wasn't broken ( I think). I doubt it would be worth all the extra time required to override Unity's system of referencing/ serializtion (assu$$anonymous$$g it's possible), but what you could do before shutting down or closing untiy when you have errors, to preserve your variables, is comment out all the code inside the offending functions until there are no errors, save the script and then the scene, and then uncommenting out those lines so you still have error messages to return to next time.
Your answer
Follow this Question
Related Questions
Why can't I to declare public the variable "Clave"? 1 Answer
How to make variable accessible by other scripts but not visible in editor? 1 Answer
Cannot assign Public GameObject variable in Inspector... 2 Answers
Referencing variables via external script? 1 Answer
How can I get a data from function to other function? 2 Answers