- Home /
Why does saving a script in runtime lose in game data?
I remember in the earlier versions of unity that when you saved any changes to a script while playing live in the engine, that it didn't lose information in game, it just updated... What happened? When I save a change in any script during run time (even non relevant), it loses all data set from awake and start functions and so forth, and I have to restart the game play to get current with any new code I set. I HATE THIS! I test out a lot concepts for my games and having to restart plays from the beginning just because I changed one simple thing in a script is driving me crazy.
Is there a way to bypass this? Am I missing something in the new version?
I have heard of player prefs but is really necessary for just updating a script while playing in the engine itself?
I have a ton of scripts so when I save in any one of them, it takes forever to update.
This is only the case for variables that are not of certain types. Like Array
's and any .NET classes are reset, while variables of type int
and float
are not.
From my experience, it's not much of a problem. I just make it a habit of not coding while it's playing.
Compared to other engines, you should be glad of the click to play function :)
Answer by Jamora · Jun 29, 2013 at 01:02 PM
Sounds like an issue with serialization. Check out this blog: http://blogs.unity3d.com/2012/10/25/unity-serialization/ . They talk about EditorWindows, but it's all applicable to the inspector as well.
Looking into it, this does seem to be the issue. Thank you. After researching, I learned about lists, but adding it to js always throws me errors- I think it has something to do with the code #pragma and that I have getcomponent within the script I need lists for. Could you please elaborate?
Any .NET classes work with #pragma strict
, you are probably just using them wrong ;)