Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Official Invitation to try out Unity Safe Mode

Discussion in '2020.2 Beta' started by MartinGram, Jul 3, 2020.

  1. _slash_

    _slash_

    Joined:
    Mar 26, 2013
    Posts:
    37
    Hi - Is there a way to manually open a project in Safe Mode?
     
  2. volblob73

    volblob73

    Unity Technologies

    Joined:
    Sep 19, 2017
    Posts:
    36
    Hi @_slash_, no Safe Mode is only available, if there is compilation error at project open.
     
    _slash_ likes this.
  3. FernandoMK

    FernandoMK

    Joined:
    Feb 21, 2017
    Posts:
    178
    Telling my first experience with SAFE-MODE

    Yesterday I migrated my HDRP project from version 2020.1 to 2020.2 beta, due to the new Features ... So, I already knew that I should fix several errors as soon as the project opened, however, safe mode went into operation right away.

    Be surprised by this, but the fact is that it helped me a lot when I migrated from version, it certainly saved me hours of work, since in a few minutes (less than 10 minutes) I had already fixed all the script problems and in project, and it was already 100% functional again (except for the SRP that I had to update the materials on, but I can't win them all:p)

    So for me, it is very practical and excellent because of its ease of operation...
    And as this was practical in my case, I really liked it :D
     
  4. VolodymyrBS

    VolodymyrBS

    Joined:
    May 15, 2019
    Posts:
    150
    Hi! I just try safe mode and have a small question.
    is it possible to run some code before compiler?
    On previous Unity versions code in precompiled assemblies marked with InitializeOnLoad could be run before compiler.
    Looks like this code runs only after compilation now.
     
    mob-sakai and Karashi-shiki like this.
  5. volblob73

    volblob73

    Unity Technologies

    Joined:
    Sep 19, 2017
    Posts:
    36
    Hi. At startup it isn't possible to run user code before compilation, if compilation is needed. It is correct that before 2019.3 that Unity at startup would load domain with user assemblies before compilation, even though if there were new scripts. This was considered a problematic and therefore the order was changed.
     
  6. vaclav_b

    vaclav_b

    Joined:
    Jun 7, 2013
    Posts:
    16
    Any plans on allowing for execution of user code in Safe Mode? Our company has custom package manager that downloads big parts of common code base when projects are downloaded from repositories and imported for the first time. Without ability to execute cusom code in safe mode we will be unable to use it.
     
  7. rosen_rusinov

    rosen_rusinov

    Joined:
    Apr 6, 2018
    Posts:
    10
    I see that the Know Issues no longer contains that updating a Package can force a project re-import, but that Just happened to me while updating a Unity Package (Code Coverage) in Safe Mode with 2020.3.3f1.

    Update:
    After waiting for 20 mins for the importing, the Editor just crashed with no Send Report dialogue.
     
    Last edited: Apr 9, 2021
  8. jayd16

    jayd16

    Joined:
    Oct 11, 2013
    Posts:
    1
    It seems like this fundamentally makes code generation impossible without using the Ignore escape hatch. Is that right?

    I would imagine its possible to fully compile and import UPM packages and then the main project in separate steps.
    That seems like it would give projects a chance to run code in a safe way. Is this possible or could it be added?

    As it is, I can't think of a nice way to implement code generation if no user code can be run before every assembly fully compiles.
     
  9. Maria_Angelova

    Maria_Angelova

    Unity Technologies

    Joined:
    Mar 3, 2020
    Posts:
    29
    We do not plan to allow user code executing in Safe Mode. You can always skip entering Safe Mode when opening a project for the first time which delivers the old behavior and your download code will run. However we do not advise opening partial projects in a mode where all asset imports are enabled. It'd be best to implement a solution which makes sure all the project's code is available on the user machine before opening it for he first time in Unity.
     
  10. Maria_Angelova

    Maria_Angelova

    Unity Technologies

    Joined:
    Mar 3, 2020
    Posts:
    29
    Updating a package in Safe Mode can cause reimports of scripting related assets. It is only non-scripting assets' imports which are postponed until exiting Safe Mode.
     
  11. Maria_Angelova

    Maria_Angelova

    Unity Technologies

    Joined:
    Mar 3, 2020
    Posts:
    29
    Could you elaborate on the setup you have in mind and the purpose of it? Which UPM pkg provides code generation needed to be able to compile other scripts in the project, does this code generation require knowing what assets are in the project and is it generating C# code or IL?
     
  12. Maria_Angelova

    Maria_Angelova

    Unity Technologies

    Joined:
    Mar 3, 2020
    Posts:
    29
    About the separate steps suggestion. The short answer is: it would break asset importing. The long answer: If a project has a scripted importer, that importer is global and affects import results of package assets as well. Importing a package's assets before all user code is compiled and loaded in a domain could potentially create wrong library artefacts and would result in non-deterministic imports for the package's assets. Deterministic import results are however a hard requirement for Unity's asset pipeline v2. Whenever this requirement is broken, ADB flags those imports and treats them differently (eg. it bans uploads to the cache server).
    Even if importers were not global, each step would involve a new domain reload, which would make the process of compiling and loading a project much slower.
     
    Last edited: Jun 14, 2021
  13. jduffy_unity

    jduffy_unity

    Joined:
    May 14, 2019
    Posts:
    4
    Currently I have a ScriptedImporter that will import protobuffer files (.proto) and generate C# classes using protoc. This lets the developer change proto files and Unity will pick up file changes and run the importer, possibly updating the C# files and causing a recompile. This flow is nice because it is very similar to the familiar auto-refresh and auto-compile flow we know and love.

    In practice this is perfectly deterministic. The generated code is not imported by the generator so there's no circular dependency problems or non-deterministic loops. I'm willing to jump through any compilation unit separation necessary to make this more obvious to the import system, (asmdef, plugin, upm etc.)

    I'm not sure this is a problem. Unity does not need to blindly reload the domain ever time at every step. Unity has no problem understanding when source files do and do not change. Code gen does not need to run on every compile. This slowness can and should only happen when generation source files are changed. Just like the visual asset import flow, this can be done in a way that makes it a rare occurrence.


    But all this being said, again I'll ask directly. It seems like the design of SafeMode (and possibly the V2 pipeline as a whole) does not account for code generation and makes code generation impossible. Is there any supported solution for this?
     
  14. dimmduh1

    dimmduh1

    Joined:
    Feb 5, 2021
    Posts:
    24
    Is there anyway to disable safe mode global and load as usual?
    Project reimports everytime when exit safemode
     
  15. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    When I open my project I receive the prompt to go save mode, after a refresh click in out of screen, or simply ignore. It loads the project with only an error for

    "[Collab] Archive::ArchiveError: Unable to perform requested action on a project that has been archived. To unarchive this project, navigate to the Developer Dashboard at http://developer.cloud.unity3d.com and click View Archived Projects. Select the 'Unarchive' button to restore the desired project."

    Is this really triggering the safe mode? We don't wanna use the collab feature anymore, hence archived.

    (edit) I came to the conclusion it was all due to Unity Hub 3.0. How can a hub create so many issues...
     
    Last edited: Jul 22, 2021
  16. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    Could we get a button in safe mode to recompile scripts?

    Sometimes something in Unity just breaks in a stupid way:
    upload_2021-7-23_8-18-34.png

    This error will solve itself if I just recompile scripts. Usually, you can do that by just right clicking and selecting "reimport" on a script file, but that's not available in safe mode. So I have to open Rider and add a whitespace somewhere.
     
  17. Romaleks360

    Romaleks360

    Joined:
    Sep 9, 2017
    Posts:
    72
    TL;DR: please add an option in Preferences to always Ignore Safe Mode

    I have a small prototype project with just a few scripts. They are often in a broken state, as I always rewrite them, and sometimes I don't have time to finish the current iteration. It's perfectly fine for me, it's my current workflow and I know what I'm doing.

    But I don't like to prototype in Safe Mode. I need the full Editor for rapid prototyping. I prefer to wait for it to load fully and then begin to code. Sometimes fixing an error is just a few seconds, but then I have to wait again for the import process to finish when I could already be in Play Mode. This slows me down a little.

    Right now I'm forced to always hit the "Ignore" button. My HDD is pretty slow so I can open the Editor and leave for a few minutes only to find out that the project wasn't loading because of the popup. That's a bit annoying.

    Having an option to permanently disable this new feature would be very nice. I know we have the "Show Enter Safe Mode Dialog" checkbox, but it does the opposite and forces the Safe Mode. It can be converted into a dropdown with two options - Always Enter and Always Ignore.

    Another suggestion - add a command-line argument. This will work only for advanced users who know the risks. Apparently, there were no risks for all those years, but whatever...
     
    Last edited: Jul 27, 2021
  18. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    291
    I just came here to ask the same thing. I do not want to open Unity in Safe Mode. Ever. Please let me disable it.
     
  19. Kabinet13

    Kabinet13

    Joined:
    Jun 13, 2019
    Posts:
    100
    I really Like this Idea! You should submit this to the unity support team, I would love to see this in the engine, and the UI you made is great, definitely include it.
     
  20. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    I may have missed this in the thread but it seems Safe Mode doesn't have the option to import a custom package under the Assets menu. Importing a custom package can sometimes be the fix required to compile scripts successfully and exit Safe Mode. You can still double click the package though to install it. Just thought I'd mention it.
     
    FernandoMK likes this.
  21. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    456
    I had a case where I needed to enter safe mode. I declined it and it started re-importing the whole library. Could it be that the library re-import is triggered if I decline the safe mode?

    Unity 2021.2.0b11