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

Why Does Clicking on a Folder Change my Inspector?

Discussion in 'Editor & General Support' started by ModLunar, Aug 21, 2020.

  1. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    372
    I have a suggestion for Unity.

    I feel like a lot of the unnecessary clicks I have to make are because clicking on folder assets in my project change my inspector.

    For example, I click on an asset (say, a ScriptableObject).
    I look at its Inspector, and say "Hey, I need to drag something into there".
    I then remember: "Ah darn! It's in that folder 3 levels deep somewhere..."
    I go clicking through folders.
    "Ah darn! My inspector changed!"
    I then have to click on the original asset.
    "Ah darn, I went to the wrong folder for the 2nd asset!"
    I then click on some more folders.
    "Ah darn! My inspector changed!"

    ...

    I don't see why clicking on folders has to change our inspector, when there is absolutely nothing for us to do with them in the Inspector.
    Maybe my proposed solution would break other things, but it's a UX problem worth looking into, even if you don't necessarily make folders not change your inspector.
    Or perhaps, make it an option in Preferences to not switch inspectors upon selecting a folder asset?

    Disclaimers:
    1. I gotta say though, the Alt + P shortcut has really helped in recent versions.
    2. I could lock my inspector, but that'll result in 4 more clicks. (2 to lock it, and 2 more to unlock it, if I remember that later...)
    3. I also don't lock my inspector, cause weird things happen (glitching and stuff, especially if it's locked for too long, between hot/domain reloads, etc..)
     
    Last edited: Aug 21, 2020
  2. Brandon_Shirk

    Brandon_Shirk

    Joined:
    Jan 12, 2020
    Posts:
    1
    Agreed, I found this thread while looking to see if there was a way to disable the folders from showing up in the inspector. It seems so unnecessary and just forces me to have to keep re-selecting objects. I would love to at least see an option to disable this!
     
    ModLunar likes this.
  3. ok8596

    ok8596

    Joined:
    Feb 21, 2014
    Posts:
    40
    I've been thinking the same for a long time.
    I don't think anything helped what I see in the Inspector when I click on a folder

    Is there an extension to solve something?
     
  4. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    372
    Oooh @ok8596 Maybe in the meantime we could write an editor extension that detects selection changes to folder assets, and selects whatever it was previously anytime a folder is selected.

    I have been quite busy lately but if I find time, I'll definitely share.
     
    Subwuwer likes this.
  5. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    While the selection workflow really needs an overhaul, I don’t believe disabling folder inspectors will do much good. On the contrary, I think it’s a feature that could be used more productively by adding custom features or info to the folder inspector. For example, if you’ve setup a custom import pipeline you can use the folder inspector to edit per-folder import rules. I’ve used folders this way in the past and wouldnt want Unity to break this.

    Overall, I think there are other UX improvements which would make this request obsolete: a builtin history panel, back/forward navigation for selection including hotkey support, the new properties panel that can be popped out of almost anything or the planned workspaces/global tabs feature.
     
    ModLunar likes this.
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I was going to go all devil's advocate and point out that the folder inspector is useful to allow you to rename the folder, especially that one time Unity had a bug where you couldn't rename anything but via the Inspector. But it looks like you can't rename the folder in the inspector anymore (I'm pretty sure that feature existed back in the day). So sadly I have to side with the OP :p
     
  7. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    139
    This! Please give us an option to ignore folders in the inspector, when clicking on them. Thanks..
     
    ModLunar likes this.
  8. ster1203

    ster1203

    Joined:
    May 17, 2020
    Posts:
    4
    100% agree

    anyone know if we can do this our self?
     
  9. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,755
    There is the lock solution listed above, but it has drawbacks, as noted above.

    There is one more even crazier lock solution that might help during times when you have a LOT of stuff to drag around:

    1. right click on the inspector window tab and open... another inspector window! (Yes, you can have more than one)

    2. lock ONE of the inspector windows, then go nuts with the other to find what you want to drag.

    This is coincidentally how you drag a particular Component into a slot, such as when there is more than a single collider and you want a very specific one.

    It's also how to drag a whole pile of things in at once, such as a list of sprites.
     
  10. ster1203

    ster1203

    Joined:
    May 17, 2020
    Posts:
    4
    Yes i am aware of that functionality, although if i can save my self a hundred clicks a day i would rather opt for that.

    I am thinking more along the lines of intercepting the Selection and if its a folder, to not update the inspector.

    any ideas?
     
  11. Albarnie

    Albarnie

    Joined:
    Oct 24, 2015
    Posts:
    18
    I've made a little editor script to do this functionality.
    If you select a folder after selecting any other asset, it will reselect the asset and lock the inspector, and unlock as soon as any other asset is selected. If your inspector is already locked it will do nothing. Hope this is useful!
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEditor;
    6. using System.IO;
    7.  
    8. //Code by Albarnie
    9.  
    10. [InitializeOnLoad]
    11. public class FolderSelectionHelper
    12. {
    13.     //The last object we had selected
    14.     public static Object lastActiveObject;
    15.     //Object to select the next frame
    16.     public static Object objectToSelect;
    17.     //Whether we have locked the inspector
    18.     public static bool hasLocked;
    19.  
    20.     static FolderSelectionHelper()
    21.     {
    22.         Selection.selectionChanged += OnSelectionChanged;
    23.         EditorApplication.update += OnUpdate;
    24.  
    25.         //Restore folder lock status
    26.         hasLocked = EditorPrefs.GetBool("FolderSelectionLocked", false);
    27.     }
    28.  
    29.     static void OnSelectionChanged()
    30.     {
    31.         if (lastActiveObject != null && Selection.activeObject != null)
    32.         {
    33.             //If the selection has actually changed
    34.             if (Selection.activeObject != lastActiveObject)
    35.             {
    36.                 //If the new object is a folder, reselect our old object
    37.                 if (IsAssetAFolder(Selection.activeObject))
    38.                 {
    39.                     //We have to select the object the next frame, otherwise it will not register
    40.                     objectToSelect = lastActiveObject;
    41.                 }
    42.                 else
    43.                 {
    44.                     UnLockFolders();
    45.                     //Update the last object
    46.                     lastActiveObject = Selection.activeObject;
    47.                 }
    48.             }
    49.         }
    50.         else if (!IsAssetAFolder(Selection.activeObject))
    51.         {
    52.             lastActiveObject = Selection.activeObject;
    53.             UnLockFolders();
    54.         }
    55.  
    56.     }
    57.  
    58.     //We have to do selecting in the next editor update because Unity does not allow selecting another object in the same editor update
    59.     static void OnUpdate()
    60.     {
    61.         //If the editor is locked then we don't care
    62.         if (objectToSelect != null && !ActiveEditorTracker.sharedTracker.isLocked)
    63.         {
    64.             //Select the new object
    65.             Selection.activeObject = objectToSelect;
    66.  
    67.             LockFolders();
    68.  
    69.             lastActiveObject = objectToSelect;
    70.             objectToSelect = null;
    71.         }
    72.         else
    73.         {
    74.             objectToSelect = null;
    75.         }
    76.     }
    77.  
    78.     static void LockFolders()
    79.     {
    80.         ActiveEditorTracker.sharedTracker.isLocked = true;
    81.         hasLocked = true;
    82.         //We store the state so that if we compile or leave the editor while the folders are locked then the state is kept
    83.         EditorPrefs.SetBool("FolderSelectionLocked", true);
    84.     }
    85.  
    86.     static void UnLockFolders()
    87.     {
    88.         //Only unlock inspector if we are the one who locked it
    89.         if (hasLocked)
    90.         {
    91.             ActiveEditorTracker.sharedTracker.isLocked = false;
    92.             hasLocked = false;
    93.             EditorPrefs.SetBool("FolderSelectionLocked", false);
    94.         }
    95.     }
    96.  
    97.     private static bool IsAssetAFolder(Object obj)
    98.     {
    99.         string path = "";
    100.  
    101.         if (obj == null)
    102.         {
    103.             return false;
    104.         }
    105.  
    106.         //Get the path to the asset
    107.         path = AssetDatabase.GetAssetPath(obj.GetInstanceID());
    108.  
    109.         //If the asset is a directory (i.e a folder)
    110.         if (path.Length > 0 && Directory.Exists(path))
    111.         {
    112.             return true;
    113.         }
    114.  
    115.         return false;
    116.     }
    117.  
    118. }
    119.  
    EDIT:
    added prefs so that it doesnt lock your inspector when you leave the editor
     
    Last edited: Sep 14, 2021
  12. ok8596

    ok8596

    Joined:
    Feb 21, 2014
    Posts:
    40
    It's quite a forced method, but.
    This is a great workaround for emergencies.
    Thank you!


    However, I would still like to see it as a basic preference in Unity...
     
  13. Albarnie

    Albarnie

    Joined:
    Oct 24, 2015
    Posts:
    18
    No problem! It definitely should be a built in feature as without custom code selecting folders is useless..
     
  14. razzraziel

    razzraziel

    Joined:
    Sep 13, 2018
    Posts:
    362
    Yeah it is unnecessary and always makes me force to use left side of project window to navigate around folders. It is a bit frustrating but that way it won't affect inspector.