Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

Hierarchy Folders

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

  1. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    482
    @Bezoro That is not intentional, I'll start working on a patch to add undo support for it. Thanks for the feedback!
     
    Bezoro likes this.
  2. FireMutant

    FireMutant

    Joined:
    Sep 2, 2013
    Posts:
    46
    Hello, I just bought your asset and thought I was doing something wrong, however, it turns out it does not flatten out the hierarchy if you use the "Enter Play Mode Options (Experimental)" in the Build Settings. I have the "Reload Scene" checked, but not "Reload Domain". I also have "Play Mode Stripping Method" in Hierarchy Folders options set to "Entire Scene When Loaded", but it doesn't flatten the hierarchy on Play. It only seems to work if I set "Reload Domain" checked, but that slows testing down immensely. I still need to test periodically with the "Reload Domain" option checked, and Hierarchy Folders seems to work fine in this situation, but it would have been nice if it worked all the time. I wonder why Scene Reloading is not triggering the flatten operation? I thought I would just bring this to your attention. Unity 2020.1.4f1, Windows 10. Thanks.
     
  3. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    482
    Hey @FireMutant , thanks for bringing this to my attention!

    I had to do some code rewriting, but have now managed to get everything working with all the different experimental enter play mode options.

    The source of the issue was that I was relying on some state automatically resetting when switching between play and edit modes, but this wasn't taking place with domain reloading disabled, so I had to handle it manually instead.

    I'll submit a new version with this fix to the asset store for approval.
     
    FireMutant likes this.
  4. FireMutant

    FireMutant

    Joined:
    Sep 2, 2013
    Posts:
    46
    Thanks SisusCo! Yes, I understand the difficulties caused by using the Enter Play Mode Options. It can cause major havoc with scriptable objects also. ;) Lots of things don't get reloaded or reinitialized without reloading the domain, but dang, once you start developing without reloading the domain each time, it is hard to go back. The efficiency gain is hard to ignore.

    Thanks for responding so quickly. I look forward to updating to the newest version when it is approved in the asset store.
     
    SisusCo likes this.
  5. silentslack

    silentslack

    Joined:
    Apr 5, 2013
    Posts:
    288
    +1 for Prefab support. I'm happy to not have the stripping happen if the folder exists inside a prefab - I'm using empty gameobjects anyway to help organize my prefabs internals so no performance hit. Could it be an opt-in option?
     
  6. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    482
    Version 1.2.0 of Hierarchy Folders is out now and introduces support for Hierarchy Folders inside prefabs!

    hierarchy-folders-prefab-support.PNG

    The feature is off by default but you can enable it in Edit > Preferences > Hierarchy Folders by changing
    the Folders In Prefabs setting to something other than Not Allowed.

    Three new modes for dealing with hierarchy folders inside prefabs are now available:

    1. Stripped at Runtime:
    Hierarchy Folders inside prefabs will be stripped when the prefab is instantiated. This takes place before any other code on the prefabs executes (including Awake, OnEnable and Start methods on all components).

    This mode can introduce a slight overhead when prefabs containing hierarchy folders are instantiated because all children of every hierarchy folder need to be reparented. If you instantiate such prefabs very often then you might want to consider alternative stripping modes or utilizing Object Pooling to avoid performing the stripping more times than necessary.

    2. Stripped at Build Time:
    Whenever you create a build all prefabs in your project will be searched for hierarchy folders. If a prefab containing hierarchy folders is found, a backup is created and then all hierarchy folders are stripped from it. Once the build has finished all stripped prefabs are restored to their original states.

    This mode can make the build process take longer in larger projects, because all prefabs in the project need to be scanned for hierarchy folders and processed as necessary.

    Additionally hierarchy folders at the root of a prefab can not be stripped at build time, because the root of a prefab can only hold a single object, so runtime stripping will still be utilized in this situation even when this mode is selected.

    3. Not Stripped:
    With this setting selected Hierarchy Folders are not stripped from prefabs at any point. As such, using hierarchy folders inside prefabs will offer no performance benefits over using empty GameObjects when grouping objects.
     
    Last edited: Jan 5, 2021
  7. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    268
    Great idea for an asset!
    I have a lot of transforms that should behave like folders.

    Here's a small bug report:
    upload_2021-1-8_2-16-8.png

    The folder icons don't fit very well if UI scale in Preferences is set to anything other than 100%.

    (however, after a while, sometimes the underlay box icon disappears)

    Does Hierarchy Folders avoid being converted to Entities, both by DOTS-Editor or (more likely to happen, because it is forced) by Subscenes? It doesn't quite seem like it right now, but it's not affecting me negatively because I had transforms there anyway. (but would love, love, LOVE to get rid of them)

    upload_2021-1-8_2-18-25.png
     
  8. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    482
    Hey @Thygrrr and thanks for the feedback!

    It looks like the system for injecting the new prefab icons to the preferences which I added in the 1.2.0 update worked unreliably. The asset database wasn't necessarily ready when the icons were initially being loaded, which could cause all the icons in the hierarchy view to be missing (except for the fallback icon with clipping issues). This issue should now be fixed in version 1.2.1.

    There is no special logic in Hierarchy Folders related to entities / DOTS at this time.

    I suspect that build stripping should still work with Subscenes, since the EntityScenes are generated based off of the scene data, and all traces of hierarchy folders are removed from all scenes during the build process. I'll need to do some testing to ensure that this is indeed the case.

    Hierarchy Folders can't contain any additional components, so adding the ConvertToEntity component to them should be impossible at least (they turn into normal GameObjects the moment that extraneous components are added). I'm not sure how the DOTS editor works, but if it functions by adding this component, then that situation should also be handled. I'll do some investigating into this too.
     
  9. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    268
    It would actually be really great if they could ([ExecuteInEditMode] components only).
    Really really great. A lot of my tooling is based on parent gameobjects having EditMode Components on them to do something complex or repetitive in edit mode.

    I think I would need to add that functionality to
    Code (CSharp):
    1. OnlyComponentAttribute.DestroyComponentIfNotAttributeHolderOrTransform
    correct?


    I suspect they would be converted because everything in a subscene is forced to convert.

    upload_2021-1-12_14-24-46.png

    But apparently... (subscene in gameobject mode)
    upload_2021-1-12_14-26-29.png

    and ...

    The entities converted in the Folders are part of the hierarchy (probably not unlike the Folders as gameobjects)
    upload_2021-1-12_14-30-31.png
    (this entity has a child buffer on it, and the child entity has a parent component on it)

    I am pretty sure this happens in a build, too. Subscenes, even though backed by Unity scenes, are not part of the scenes in a build, so I don't know what Preprocessing steps can actually run on them.

    No, everything in a subscene is forced to convert as if it had the behaviour. You can't deactivate this. It will get fed to a GameObjectConversionSystem.

    upload_2021-1-12_14-24-46.png

    It might require a Conversion System running in BeforeGameObjectConversionGroup to work around this. What can I call on a HierarchyFolder for it to "do its magic"? And... I fear it needs to be reversible. (I'll volunteer to sort out such a system and can share the code, it's likely just ~10 lines of actual code or so)
     

    Attached Files:

  10. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    482
    Hey @Thygrrr , sorry for not getting back to you earlier! I've had quite a busy week.

    I've been thinking about this for some time too, that it might be a good idea to allow some components to be added on Hierarchy Folders for their editor-time functionality.

    I've thought about adding an interface like IHierarchyFolderComponent which components could implement to let the system know they should be allowed on hierarchy folders. The downside with this approach is that it would not be a good solution for components from other third party assets, where you might not be able to make modifications to the components. Also it would introduce a dependency between the components and hierarchy folders which is not optimal.

    Having a whitelist in the preferences where users can add any component types they want to be allowed on hierarchy folders is another approach which I think would work better, as it would avoid the aforementioned issues.

    OnlyComponentAttribute yes, and also HierarchyFolderUtility.HasSupernumeraryComponents. I believe those are the only things that would need to be modified, but I'm not 100% sure without doing some testing.

    Ah yes, that's a good point! Build post processing probably doesn't affect those scenes since they're not included in the build settings as such.

    HierarchyFolderUtility.ApplyStrippingType can be used to strip an entire scene of hierarchy folders and
    HierarchyFolderUtility.CheckForAndRemoveHierarchyFoldersInChildren can be used to strip all hierarchy folders recursively in children of a root transform. Neither one of them are reversible processes though I'm afraid, so these would only be usable if acting on a copy of the source scene (or creating a backup first which is restored after the process is done).

    It should also be possible to create a fully reversible process which stores the child hierarchies of all hierarchy folders and then flattens them - but doesn't destroy them. I actually did some testing with a system like this when I was working on prefab support, but it ended up not being a viable solution for prefabs assets, so that code is not currently included with the asset. The HierarchyFolderUtility methods can be called with StrippingType.FlattenHierarchy though, so they could maybe be used for the flattening portion of such a system.

    Thank you for offering to help with this! I can also try looking into this on my end, but I'm afraid I don't have much experience with the ECS right now, so it might take me a while to figure everything out - so your help is much appreciated :)
     
  11. ch1ky3n

    ch1ky3n

    Joined:
    Oct 26, 2017
    Posts:
    31
    Why do I get these errors all of sudden? it was fine before.
    I try to create a new empty scene and play it and the errors still appear!
    Weird

    here are the errors:

    Code (CSharp):
    1. Assertion failed on expression: 'gRefreshReentrancyCount > 0'
    2. UnityEngine.StackTraceUtility:ExtractStackTrace ()
    3. Sisus.HierarchyFolders.HierarchyFolderBuildPrefabRemover:RestoreBackups (bool) (at Assets/Plugins/Sisus/Hierarchy Folders/Code/Editor/HierarchyFolderBuildPrefabRemover.cs:282)
    4. Sisus.HierarchyFolders.HierarchyFolderBuildPrefabRemover:.cctor () (at Assets/Plugins/Sisus/Hierarchy Folders/Code/Editor/HierarchyFolderBuildPrefabRemover.cs:53)
    5. UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes (System.Type[])
    6.  
    and

    Code (CSharp):
    1. StopAssetEditing invoked without a call to StartAssetEditing. Please make sure that for every call to StopAssetEditing there is at least one call to StartAssetEditing
    2. UnityEngine.StackTraceUtility:ExtractStackTrace ()
    3. Sisus.HierarchyFolders.HierarchyFolderBuildPrefabRemover:RestoreBackups (bool) (at Assets/Plugins/Sisus/Hierarchy Folders/Code/Editor/HierarchyFolderBuildPrefabRemover.cs:282)
    4. Sisus.HierarchyFolders.HierarchyFolderBuildPrefabRemover:.cctor () (at Assets/Plugins/Sisus/Hierarchy Folders/Code/Editor/HierarchyFolderBuildPrefabRemover.cs:53)
    5. UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes (System.Type[])
    6.  
     
  12. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    482
    Hi @ch1ky3n

    It seems there was an issues with the new prefab build stripping system. After a build has been made with prefab stripping enabled it would try to perform asset database editing during initialization even if there were no more stripped prefab backups that needed to be restored. This would result in errors in newer Unity versions than what I had used in my testing.

    I've created a fix and will publish an update with it soon; I'll also PM you the updated package so you don't need to wait for asset store validation.

    Thank you for letting me know about the issue!
     
  13. ch1ky3n

    ch1ky3n

    Joined:
    Oct 26, 2017
    Posts:
    31
    Done and Gone in less than 24 hours , You are awesome!
     
    SisusCo likes this.
  14. Tirus

    Tirus

    Joined:
    Aug 9, 2013
    Posts:
    6
    Stripping Folders in Prefabs that are embedded in other prefabs at Build Time does not work (at least in 2020.3.5f1).

    Setting the parent of a transform which resides in a Prefab Asset is disabled to prevent data corruption
    UnityEngine.StackTraceUtility:ExtractStackTrace ()
    Sisus.HierarchyFolders.HierarchyFolderUtility:CheckForAndRemoveHierarchyFoldersInChildren (UnityEngine.Transform,Sisus.HierarchyFolders.StrippingType,bool,System.Collections.Generic.List`1<UnityEngine.GameObject>) (at Assets/Sisus/Hierarchy Folders/Code/HierarchyFolderUtility.cs:147)
    Sisus.HierarchyFolders.HierarchyFolderUtility:CheckForAndRemoveHierarchyFoldersInChildren (UnityEngine.Transform,Sisus.HierarchyFolders.StrippingType,bool,System.Collections.Generic.List`1<UnityEngine.GameObject>) (at Assets/Sisus/Hierarchy Folders/Code/HierarchyFolderUtility.cs:154)
    Sisus.HierarchyFolders.HierarchyFolderUtility:CheckForAndRemoveHierarchyFoldersInChildren (UnityEngine.Transform,Sisus.HierarchyFolders.StrippingType,bool) (at Assets/Sisus/Hierarchy Folders/Code/HierarchyFolderUtility.cs:86)
    Sisus.HierarchyFolders.HierarchyFolderBuildPrefabRemover:StripPrefab (UnityEngine.GameObject,Sisus.HierarchyFolders.StrippingType) (at Assets/Sisus/Hierarchy Folders/Code/Editor/HierarchyFolderBuildPrefabRemover.cs:218)
    Sisus.HierarchyFolders.HierarchyFolderBuildPrefabRemover:StripHierarchyFoldersFromAllPrefabs (Sisus.HierarchyFolders.StrippingType) (at Assets/Sisus/Hierarchy Folders/Code/Editor/HierarchyFolderBuildPrefabRemover.cs:171)
    Sisus.HierarchyFolders.HierarchyFolderBuildPrefabRemover:OnPostProcessScene () (at Assets/Sisus/Hierarchy Folders/Code/Editor/HierarchyFolderBuildPrefabRemover.cs:111)
    UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)



    This error also destroys you prefabs in the process, so better have a commit you can go back to when trying.
     
  15. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    482
    @Tirus Oh you're right, I totally failed to consider nested prefabs for the build-time prefab stripping o_O Thank you for bringing this to my attention and sorry for the trouble! I pushed a hotfix to make the build stripping system for now just skip over any nested prefabs. Optimally it should instead unpack them first and then flatten them, but I'll look into implementing this for the next patch.

    All stripped prefabs usually get restored to their original states during the OnPostprocessBuild event if the build finishes normally. If the build process fails for some reason after it has already processed the first scene, they currently only get restored during the next assembly reload event - which isn't very good if it doesn't happen immediately after a build has failed. I'll give the backup restoring system another look and see if I could make it restore the backups more reliably immediately after build failure.
     
  16. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    482
    I pushed a second update, and with it the systems should now be able to always restore stripped prefabs right after building finishes even in the event that it should fail at any point of the process.

    Build-time stripping of prefabs can now also handle nested prefabs properly by unpacking everything recursively before flattening the hierarchy and removing the hierarchy folders (this is necessary since these operations are not allowed for objects inside prefab instances).
     
unityunity