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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Hierarchy Folders

Discussion in 'Assets and Asset Store' started by SisusCo, Nov 27, 2019.

  1. Renoker

    Renoker

    Joined:
    Aug 14, 2022
    Posts:
    1
    Hi! I just bought this to use with a prefab, and it's not working, despite enabling the setting. I can create the folder within the prefab, but when I try to drag an object onto it, I get "Children of a Prefab instance cannot be deleted or moved, and components cannot be reordered. You can unpack the Prefab instance to remove its Prefab connection.

    I've set the "folders in prefabs" section to all the different ones and tried it. I also restarted the client. Any ideas how to fix? I'd really like to have this functionality.

    (Unrelated, but a really cool feature would be importing collections from blender FXB files as folders)
     
  2. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    886
    Hi @Renoker , I'll look into the issue, thanks for letting me know about it!
     
  3. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    886
    @Renoker I think what you're running into is actually probably just normal prefab instance behaviour in Unity.

    So with all prefab instances, you can only drag and drop new GameObjects underneath them at the tail end of the child hierarchy. So if you have, say, a prefab instance with two children, you can't drag and drop a new GameObject at the first child slot, nor the second child slot, but only at the third child slot.

    add-prefab-child.gif

    Let me know if you're experiences some issues other than this :)
     
  4. SpyrosUn

    SpyrosUn

    Joined:
    Nov 20, 2016
    Posts:
    144
    Hi !

    I am noticing on my Mac that folders do not appear to be opened up when they are collapsed. Also, looking a bit weird :/

    I am not sure whether the plugin has some issues become i also use Rainbow Hierarchy with this one.

    How do you change the icons of a folder ? When click option(alt for mac) to switch the icons, i get the rainbow hierarchy popup. Is it become yours is using the same hotkey ? or is there another one?
     

    Attached Files:

  5. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    886
    Hi @SpyrosUn!

    It looks like for some reason the correct Hierarchy Folder icons have failed to load and a fallback icon is being used, resulting in that ugly clipping o_O

    The icons can be customized in Project Settings > Hierarchy Folders, but in this situation I don't think it would help since they don't seem to be getting used.

    2022-08-31 08_54_38-Greenshot.png

    I'll take a look at the icon loading logic and try to improve its reliability. Could be that the asset database works a bit differently on Mac than on my Windows and I need to delay the loading until its ready or something.

    If you want to disable Hierarchy Folders' custom icons and use Rainbow Folders' icons instead, there's also a checkbox in the Project Settings called Enable Hierarchy Icons that you can untick (note that you might need to restart the Editor for this setting to take effect).
     
  6. _antifun_

    _antifun_

    Joined:
    Oct 1, 2016
    Posts:
    5
    I bought the asset and it's nice :) I'd just suggest an explanation if you need to change anything in your project when using the folders, for example how GameObject.Find() behaves with it (and even if it's the same as a normal GO 'folder' just optimized, then write that there's no changes needed.)
     
  7. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    886
    @_antifun_ That's a great idea - I could add something about that to the documentation!

    To quickly answer your question:
    As long as you have hierarchy folder stripping enabled (or disabled; as long as it's the same for both) for both play mode and builds, there should be no practical difference between them.


    If however you do decide to disable stripping in edit mode but enable it for builds, then it becomes important for you to keep one rule in mind when writing code: everything should continue to work regardless of the exact hierarchical grouping of your scene objects.

    This is good practice in general, but becomes even more important when only stripping hierarchy folders from builds.


    One pitfall to avoid is searching for GameObjects using their full hierarchy path, if one or more of the objects in the parent chain are hierarchy folders.
    Code (CSharp):
    1. public class FindPlayerExample : MonoBehaviour
    2. {
    3.     GameObject AvoidThis()
    4.     {
    5.         // This finds a game object named "Player" under a parent named "Actors".
    6.         // This might work in the editor, but fail in builds, if the parent is a hierarchy folder
    7.         // and build stripping has been enabled for builds but not play mode.
    8.         return GameObject.Find("Actors/Player");
    9.     }
    10.  
    11.     GameObject DoThisInstead()
    12.     {
    13.         // This finds a game object named "Player".
    14.         // This will  work regardless of what parents the object has.
    15.         return GameObject.Find("Player");
    16.     }
    17.  
    18.     GameObject OrThis()
    19.     {
    20.         // This finds a game object with the tag "Player".
    21.         // This will also work regardless of what parents the object has.
    22.         return GameObject.FindWithTag("Player");
    23.     }
    24.  
    25.     Player ThisWorksAsWell()
    26.     {
    27.         // This finds a game object with the component Player attached to it.
    28.         // This will work regardless of what parents the object has as well.
    29.         return Object.FindFirstObjectByType<Player>();
    30.     }
    31. }
    Another thing that could be problematic in some situations is searching for objects in the parent hierarchy of a game object.

    For example, if you group your game objects under a hierarchy folder in the editor, and build stripping has been enabled for builds but not play mode, then calling transform.root will give different results in play mode and in builds.

    Hierarchy Folders comes with some extension methods to help write code that acts as if hierarchy folders did not exist in the hierarchies, even if build stripping hasn't been enabled for play mode.
    Code (CSharp):
    1. public class EntityRootExample : MonoBehaviour
    2. {
    3.     Transform AvoidThis()
    4.     {
    5.         // This returns the topmost transform in the hierarchy.
    6.         // This can give a different result in builds and in the editor, if the root object is
    7.         // a hierarchy folder, and build stripping has been enabled for builds but not play mode.
    8.         return transform.root;
    9.     }
    10.  
    11.     Transform DoThisInstead()
    12.     {
    13.         // This returns the topmost transform in the hierarchy, ignoring hierarchy folders.
    14.         // This will always give the same result in builds and in the editor, even if
    15.         // the root object is a hierarchy folder, and build stripping has been enabled
    16.         // for builds but not play mode.
    17.         return transform.GetRoot(skipHierarchyFolders: true);
    18.     }
    19.  
    20.     Entity OrThis()
    21.     {
    22.         // This finds a game object with the component Entity attached to it.
    23.         // This will always give the same result in builds and in the editor, even if
    24.         // the root object is a hierarchy folder, and build stripping has been enabled
    25.         // for builds but not play mode.
    26.         return GetComponentInParent<Entity>();
    27.     }
    28. }