Unity Safe Mode is available in Unity 2020.2 beta. This improves how Unity behaves when opening a project that has script compilation errors.
If there are compilation errors at Editor startup, you will be prompted to enter Safe Mode. This mode is designed to provide the best environment for resolving compilation errors, so that you can quickly return your project to a functional state, without waiting for all of your project’s assets to be imported. This feature will simplify and speed up the process of upgrading a project to a new Unity version, and it will help teams working on large projects by reducing the number of cases in which the library folder contains incorrect import artifacts.
We are always looking to improve the experience of working with Unity based on feedback from you and our internal production teams. One of the areas identified was how Unity behaves as errors are detected and reported during initial script compilation and asset importing when upgrading a project.
Consequently, we have recently improved how Unity behaves during startup and how it reports compilation errors that happen during startup to users, as well as the initial process of bringing up the environment or domain that contains their project. In this post, we want to share what we did in 2020.2 to solve your problems in this area and invite you to provide feedback.
In practice, many projects depend on scripts being present for post-processing or custom scriptable importers, or simply to correctly deserialize Prefabs – either through code directly in your project or the packages you depend on. In the presence of compilation errors in scripts and packages, their respective assemblies cannot be loaded and, since they couldn’t be compiled, their code cannot execute. After the compilation is completed, previous versions of Unity load the project partially and continue to import all assets. This partial project state causes a range of problems that we are addressing with the introduction of Safe Mode.
In Unity 2020.2, if any compilation errors occur during startup, Unity now prompts you to enter the new Safe Mode, where you can manage your project, solve compilation errors and bring the project environment back into a working state.
In Safe Mode, Unity provides a minimal version of the Editor user interface, with limited functions, which help you focus on resolving compilation errors before the rest of your project is opened. This interface includes, but is not limited to:
Safe Mode never allows managed code to run from your project or its packages. This ensures the Editor in Safe Mode is always fully functional and reliable, even when opening a project that is in a very broken state.
Unity automatically exits Safe Mode when it detects there are no more compilation errors. When it exits Safe Mode, your project is imported in full and the Editor restores its normal full functionality.
By addressing these issues, Safe Mode greatly improves the process of upgrading projects and significantly reduces the risk of projects needing to be rolled back or recovered.
Using Unity Safe Mode to fix a wrong declaration for a Vector3 inside a Unity project
In previous versions, Unity in batch mode would also partially load a project with compilation errors and proceed to import all assets. Once the imports are finished, by default, it would exit with an error message unless instructed otherwise via command line arguments. We changed this behavior in Unity 2020.2: now batch mode, by default, no longer makes use of partial project load and asset imports, and exits with an error message as soon as compilation errors are detected. This makes batch mode completion much faster in the presence of compilation errors. It also prevents continuous integration (CI) systems from populating the project’s asset cache server with incorrect import artifacts, which causes the problems listed above not only locally on one computer, but for everyone working on the project.
We are looking for feedback on all aspects of the new Safe Mode state of Unity. We are especially interested in knowing if we have missed functionality that you feel is important to have present during Safe Mode. You can provide feedback in the forum.
Our R&D and QA staff work hard to make sure that our releases are stable, our features are polished and the workflows help you be more productive, but we couldn’t do it without all the feedback from the community.
With Unity 2020.2, we’re continuing our 2020 focus on performance, stability, and workflow improvements. Join the beta and let us know what you think about the upcoming tools.
Is this article helpful for you?
Thank you for your feedback!