4
\$\begingroup\$

I have a relatively large project (about 8GB) and it is constantly reimporting itself over and over, to the point that I spend 80% of my time waiting for Unity to:

  • Reimport everything
  • Stop hanging.

Even for the smallest of changes (ie. removal of a comment on one line in a script), or changing import settings on an asset can cause these long hangs and reimports.

To make matters worse, this project is also synced over UnityCollabBETA, which throws manual/selective import (auto-refresh is forced on) out the window.

I've also read up that other programs locking asset files (to read them) can also cause Unity to reimport everything as opposed to simply doing a selective import (only reimporting things that has been changed).

I've tried creating blacklists for my auto-backup programs, anti-viruses and anything that would snoop around and/or mess with the Unity Project folders. However, despite those programs not accessing anything, Unity still reimports the whole project every time I alt-tab out.

The only workaround I've found so far is to just kill Unity every time it does it and relaunch it as for some reason it processes the actual changed files first, then hangs itself by going through everything else.

It is also worth noting that I/O is maxed up by Unity (due to the sheer size of the project) and CPU/GPU usage are relatively low (does not exceed 20-30%, assuming nothing else is running in the background).

Note: This has persisted through installs and computers.


Question

How do I stop Unity from reimporting everything without constantly killing Unity?

\$\endgroup\$
3
  • \$\begingroup\$ Is it safe to assume you've reported this to the Unity dev team through the bug tracker? Have they offered any suggestions as to the cause? \$\endgroup\$
    – DMGregory
    Commented Apr 1, 2017 at 12:19
  • 1
    \$\begingroup\$ @DMGregory I haven't as the project is too big to upload (well on my internet connection anyway). Could you point to me where I could do so? (Note: Was banned from Unity Answers by a problematic moderator) \$\endgroup\$
    – aytimothy
    Commented Apr 1, 2017 at 12:21
  • \$\begingroup\$ The usual approach here is to create a minimum, complete, verifiable example. So, copy your project and start deleting things bit by bit. If the problem stops, that's a good clue that one of the deleted files had something to do with it. If it persists, then you'll slim down the project to something of a shareable​ size. \$\endgroup\$
    – DMGregory
    Commented Apr 1, 2017 at 12:23

3 Answers 3

3
\$\begingroup\$

One option which can in some cases greatly decrease the waiting time after small script changes can be to disable domain reloading and to disable scene reloading in your project settings. You can find this under File -> Project Settings -> Editor. Enable "Enter Play Mode Options" and then leave "Reload Domain" and "Reload Scene" disabled.

However, be aware of the side-effects:

  • Any static variables in your scripts will no longer get reset to the initial values when you restart the game. They will only reset when you restart the Unity editor. A possible workaround for that problem can be a [RuntimeInitializeOnLoadMethod] which resets all static variables.
  • Any arrays which are exposed inspector properties but have no entries in the inspector, will be null instead of arrays with 0 entries.
  • On switching from editor mode to play mode, [ExecuteInEditMode] scripts won't get disabled and re-enabled as usual and there won't be an obligatory OnValidate() call for all scripts either.

None of these behavior differences will affect the game builds, but might result in some unexpected behavior during development.

\$\endgroup\$
3
\$\begingroup\$

Another way to mitigate reimports is for example to enable Parallel Import in the Project Settings/Editor/Asset Pipeline section, or changing how many cores the Unity Editor can use for imports (Preferences/Asset Pipeline) etc. This isn't a real solution, but I've found some salvation in atleast doing this when I didn't want to do the more bug-risky methods described by the others.

Edit 1: As noted by the first comment below, this could potentially cause issues with some libraries that use importers relying on global state only compatible with a single thread.

Edit 2: You can also consider using Assembly Definitions for parts of code that are separable, like your main scripts and editor-scripts. I use a git submodule with assembly definitions for my projects for tools that do not need to be recompiled every time a gameplay script or editor script is changed.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I didn't know that setting was there! I was surprised it wasn't enabled by default, but I guess some custom importers written for previous versions might rely on modifying some global state, leading to confusing bugs if this behaviour changed silently. Still, it would be nice if Unity could recommend this setting in new projects or if it can detect you're not using any custom importers outside a "safe" list. \$\endgroup\$
    – DMGregory
    Commented Apr 23, 2023 at 15:58
  • \$\begingroup\$ Yeah, it's definitely something to consider enabling for all new projects, just like the settings suggested by others here. I haven't personally encountered issues with these yet apart from the one time I tried making a weird singleton-based level editor that was supposed to work in edit mode, while having domain reloading off. This is moreso an issue with code quality than anything however. \$\endgroup\$
    – Mikkel
    Commented Apr 28, 2023 at 8:26
  • \$\begingroup\$ I forgot to add a mention of Assembly Defintions. Using these can at some scales dramatically decrease re-compilation times, especially when working with code that is not used anywhere else, for example (and especially!) editor scripts! \$\endgroup\$
    – Mikkel
    Commented Apr 28, 2023 at 8:39
0
\$\begingroup\$

I am guessing you have some scripts in your project that is causing this, as it is possible to override Unity's default behavior when it comes to importing assets. I would try to copy the project, remove all scripts and see what happens.

If this removes the problem, then looking for any scripts that imports UnityEditor should help narrow it down further

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .