- Home /
Playmode script recompilation - static vars lost?
Is it normal for a large Unity project to survive script recompilation when in playmode, or once a project reaches a certain size and complexity, do most of you just give up on trying to write code that can survive recompilation?
Other than all static vars resetting to their default values, what else happens when scripts are reloaded?
Are there any recommended design patterns which help to increase reload resiliency?
No. I'm pretty sure script recompilation at runtime screws everything up, every time. Basically, try to avoid it at all costs.
It sure is nice when I can get it to work on small projects though!
$$anonymous$$akes debugging dramatically more fun when you can change a script and then playtest that change without restarting your game.
Only those things that can be serialized are preserved. So usually all private, static and all other non-serializable values are lost.
There's no way around this. Unity have to recreate all your objects.
Fair enough. I am still curious though - can most large Unity games survive playmode recompilation, or at some point does everyone just give up and resort to restarting their game after every script tweak?
Yep, that's what I have been doing - but it gets more burdensome as your project continues to grow. From what I have heard so far, I guess I'll be in good company if I give up now ;)