There’s a preferences item called “Script Changes While Playing” with the option to “Recompile and Continue Playing”. This sounds like a nice feature, but it feels abandoned.
The two other options make sense depending on personal taste. We can either have playmode stop when scripts are recompiled or delay recompiling until playmode is exited. Both are valid options and work well 99.9% of the time.
But the third option, compiling scripts and continuing playmode seems like it won’t ever work. As a user, I would have to ensure that all of my scripts serialize their complete state. Either by using only serializable member variables or by restoring objects during OnEnable, for example. All of this is a lot of extra work, but it’s possible and can be immensely beneficial to testing and iterating. Basically, changing scripts while playing the game can alleviate many different issues such as long enter playmode times or generally avoid having to play portions of the game or investing in additional testing/debugging logic.
However, any chance of implementing recompile during playmode is blocked by Unity provided components. I can’t say for certain which these are, but basically, whenever I try to use recompile during playmode I get a spew of warnings like:
Warning Message
The referenced script (Unknown) on this Behaviour is missing!
0x00007ff613a7195c (Unity) StackWalker::GetCurrentCallstack
0x00007ff613a77af9 (Unity) StackWalker::ShowCallstack
0x00007ff614264823 (Unity) GetStacktrace
0x00007ff61515aa6a (Unity) DebugStringToFile
0x00007ff613a12ba8 (Unity) SerializableManagedRef::RebuildMonoInstance
0x00007ff613979c0c (Unity) SerializableManagedRefTransfer::RestoreBackup
0x00007ff613a13221 (Unity) SerializableManagedRefsUtilities::RestoreBackups
0x00007ff61398cc29 (Unity) MonoManager::EndReloadAssembly
0x00007ff61399397d (Unity) MonoManager::ReloadAssembly
0x00007ff614129ea5 (Unity) ReloadAllUsedAssemblies
0x00007ff613e6e254 (Unity) Application::TickTimer
0x00007ff61426a561 (Unity) MainMessageLoop
0x00007ff61426e1f6 (Unity) WinMain
0x00007ff615dca0a2 (Unity) __scrt_common_main_seh
0x00007ffd08657c24 (KERNEL32) BaseThreadInitThunk
0x00007ffd0a26d4d1 (ntdll) RtlUserThreadStart
Alongside a few exceptions caused by UIElements/UI Toolkit and various packages that don’t deal with recompile during playmode. Sometimes, even the Unity UI components break, depending on their setup.
I haven’t investigated all cases, but I can tell that I’ve been trying to convince my team to make scripts recompile in playmode since 2014 but it never worked because after doing the groundwork, we end up blocked by some Unity system that doesn’t support it.
So, what is Unity’s stand on this? Is recompile during playmode supported or not? I actually don’t mind, if the option were removed because it was deemed too much trouble, but if it stays, I think Unity should put in the effort of supporting it with all of the official packages, at least with UI, PostProcessing, and the sort of common runtime features. ![]()