Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Can you nest AssetDatabase.StartAssetEditing calls?

Discussion in 'Editor & General Support' started by CDF, Aug 14, 2019.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    853
    Just wondering if Unity respects multiple calls to AssetDatabase.StartAssetEditing and AssetDatabase.StopAssetEditing?

    example:

    Code (CSharp):
    1. public static void DoHeavyAssetProcessing(Object[] objects) {
    2.  
    3.     AssetDatabase.StartAssetEditing();
    4.  
    5.     foreach (Object obj in objects) {
    6.  
    7.         DoAssetProcessing(obj);
    8.     }
    9.  
    10.     AssetDatabase.StopAssetEditing();
    11. }
    12.  
    13. public static void DoAssetProcessing(Object obj) {
    14.  
    15.     AssetDatabase.StartAssetEditing();
    16.  
    17.     //do some processing on the object which might call AssetDatabase methods
    18.  
    19.     AssetDatabase.StopAssetEditing();
    20. }
    Both methods can be called independently by the User and both should respect that AssetDatabase might be modified, so they both use AssetDatabase.StartAssetEditing.

    When AssetDatabase.StopAssetEditing is called in "DoAssetProcessing", does Unity respect that there is currently > 1 call to StartAssetEditing and so doesn't Stop until the final StopAssetEditing call?

    I would hope the implementation is something like:

    Code (CSharp):
    1. public static void StartAssetEditing() {
    2.  
    3.     startEditingCalls++;
    4.     //internal Unity stuff
    5. }
    6.  
    7. public static void StopAssetEditing() {
    8.  
    9.     startEditingCalls--;
    10.  
    11.     if (startEditingCalls <= 0) {
    12.  
    13.         startEditingCalls = 0;
    14.  
    15.         //start the imports now
    16.     }
    17. }
     
unityunity