Search Unity

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:
    1,331
    Hi @Renoker , I'll look into the issue, thanks for letting me know about it!
     
  3. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,331
    @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:
    1,331
    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:
    1,331
    @_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. }
     
  8. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    334
    @SisusCo I seem to be running into errors just when running the latest Hierarchy Folders (1.2.7) with the latest Power Inspector (1.6.8).

    For example:

    Code (csharp):
    1. Assets/Sisus/Hierarchy Folders/Code/Editor/PowerInspectorIntegration/HierarchyFolderDrawer.cs(30,25): error CS0115: 'HierarchyFolderDrawer.HeaderHeight': no suitable method found to override
    2.  
    Any ideas?
     
  9. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,331
    @Colin_MacLeod It seems that this is because of a namespace change that has taken place in more recent Unity versions for one of the built-in classes. Running Unity's API Updater should be able fix it I think.
    Run API Updater.png

    I'll submit an update to the asset store with the updated namespace as well.
     
    Colin_MacLeod likes this.
  10. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    334
    @SisusCo Running 2021.3.22f1, I don't have that menu item.
     
  11. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,331
    @Colin_MacLeod Oh, it looks like they've removed the menu item at some point, the documentation no longer mentions the ability to run it manually. Well, I've sent you the updated package in a PM.
     
    Colin_MacLeod likes this.
  12. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    334
    Oh, man! Thank you very much. That was very kind of you.
     
    SisusCo likes this.
  13. pappaxray2

    pappaxray2

    Joined:
    Mar 30, 2016
    Posts:
    12
    Hi, we had an issue where different branches of the project on the same machine would backup to the same directory. HF would also fail when trying to delete read only files (LFS locking) so data from one branch on our CI machine could be restored onto a different branch. We made a fix locally, shared here if it'd be useful to you @SisusCo
     

    Attached Files:

  14. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,331
    Thank you so much for sharing this @pappaxray2 , those are great improvements!
     
  15. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    334
    @SisusCo it seems using Hierarchy Folders in an ECS subscene causes various entities to appear in the wrong place.
    In particular, when baking ECS animations (using the GPU ECS Baking assets) attachments appear in the wrong place.

    This only seems to happen when you locate the ECS Authoring entity under a Hierarchy Folder. I'm not sure specifically what's happening, but wanted to let you know - it really caught me out as I'm new to ECS and spent ages debugging the issue, never imagining it might be the folder.

    (When I move the entity gameobject outside the folder, it works as expected.)

    Not looking for any solution on your part here @SisusCo - I'll just not use Hierachy Folders in subscenes which is fine - but I wanted to let you know in case you or anyone else hits the same thing!
     
  16. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,331
    Thanks for the heads up @Colin_MacLeod !

    Adding a custom baking system that would handle stripping Hierarchy Folders from subscenes is something I've been thinking about implementing at some point for quite some time now.

    I had some trouble figuring out a way to implement that in a seamless/automatic way in earlier ECS versions. Now that the Entities package has reached 1.0+ version and is a lot more stable than it was a few years ago, and I'm a bit more familiar with ECS and its baking system as well, it would be a good time to take another look soonish.
     
    Colin_MacLeod likes this.
  17. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    334
    That's cool. I'm not sure why it breaks just now, but breaks it does. It stays broken even if I go into debug mode and remove the Hierarchy Folder script.