Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Where is the Desired Import Worker Count stored?

Discussion in 'Asset Importing & Exporting' started by BATOVI_Games, Jun 13, 2023.

  1. BATOVI_Games

    BATOVI_Games

    Joined:
    Jun 3, 2014
    Posts:
    7
    Hello,

    I am trying to write a script that detects certain PC specs/configs and then sets import settings accordingly.

    It seems to me that by default the thread count for import is set to 25% of CPU max threads as per
    Code (CSharp):
    1. [Edit] -> [Preferences]
    This is far from ideal as you are effectively handicapping the import speed by default.

    What is further far from ideal is that there is another confusing setting under
    Code (CSharp):
    1. [Project Settings] -> [Editor] -> [Asset Pipeline] -> [Parallel Import] and [Desired Import Worker Count]
    I want this checkmark and the amount of threads to change via code and I cannot seem to find where that is stored.

    Looking at version control after changing this setting, I see no change in any of our files in the repository, but resetting the repository either discarding files individually through git restore or resetting to previous commit through reset --HARD, reverts the setting so that Parallel Import is disabled and Worker count is only 1.

    Furthermore there seems to be an invalid DWORD value stored at registry, named DesiredImportWorkerCountPctOfLogicalCPUs_h1340498813 which is not human readable and is not ideal to edit either as it belongs in Windows realm, not linux nor macos.

    What is the proper way to set Parallel Import through script?

    I'm using Unity 2021.3.9f1, is this fixed on newer versions?

    Also, for curiosity, what's with all these numbers at the end of the registry key name?

    Thanks for your time
     
  2. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    176
    This is accessible using the EditorPrefs.GetFloat api, the key used being
    DesiredImportWorkerCountPctOfLogicalCPUs
    .
    You can also use SetFloat to change the value. It should work on any platform.
    The details on where it is stored on each platform are on the main API documentation page: EditorPrefs

    Parallel Import is accessible through
    EditorSettings.refreshImportMode
    and desired import worker count is under
    EditorUserSettings.desiredImportWorkerCount
    .
    I'm not sure why they are all so much under different APIs, but I can give a breakdown of where it goes:
    EditorPrefs means this is shared across all your projects on your machine but not shared in your repository.
    EditorSettings should be saved in your project settings and thus shared in your project repository, so it is exclusive to each project but shared between users.
    EditorUserSettings means it is local to this project, and not shared between users.
     
    Last edited: Jun 14, 2023
  3. BATOVI_Games

    BATOVI_Games

    Joined:
    Jun 3, 2014
    Posts:
    7
    Thanks very much for reaching out! This does the trick.

    Your answer is much insightful.

    I also found AssetDatabase.ActiveRefreshImportMode which makes me doubt if I should use your suggestion of EditorSettings.refreshImportMode, or whether if one influences the other. I havent quite gone through documentation for neither yet but will be shortly.

    Maybe there could be some redesign here on the APIs specially since on GUI these options are bunched together which for beginners like me who don't have the whole story on it looks contradictory/convoluted.

    Hope you have a great day
     
  4. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    175
    To add to @bastien_humeau 's reply,
    The EditorUserSettings are stored in the Library folder (under Library/EditorUserSettings.asset).
    The reason for them being there, like Bastien mentioned, is that the settings are local to the project and not shared between users, meaning that if 2 team members have differing machine specs (as is usually the case) they can set the number of workers to whatever they see fit for their project.

    Additionally, to ensure parallel import is enabled you need to change the import mode as well, like so:
    AssetDatabase.ActiveRefreshImportMode = AssetDatabase.RefreshImportMode.OutOfProcessPerQueue;


    I do agree the API could use a bit of love, since it does seem a bit scattered.
    I'm thinking something like AssetDatabase.EnableParallelImport(desiredWorkerCount, standbyWorkerCount, idleShutDownTimeout) and then AssetDatabase.DisableParallelImport() , what do you think?

    I think those should be trivial to add, since under the hood we'd still call the APIs in the EditorUserSettings.
    For completeness, they would be:
    Code (CSharp):
    1.  
    2. AssetDatabase.ActiveRefreshImportMode
    3. EditorUserSettings.desiredImportWorkerCount
    4. EditorUserSettings.standbyImportWorkerCount
    5. EditorUserSettings.idleImportWorkerShutdownDelayMillisec
    Setting all those is how you enable parallel importing correctly.

    If you want to do it via command line:
    Unity.exe -refreshImportMode (outofprocessperqueue | inprocess) -desiredWorkerCount 4 -standbyWorkerCount 4 -idleWorkerShutdownDelay 60000


    Note the (outofprocessperqueue | inprocess) maps to the values of AssetDatabase.ActiveRefreshImportMode, so pick just one! :D
     
    Last edited: Jun 15, 2023