Search Unity

TreeView element

Discussion in 'UI Toolkit' started by kr_vs, Apr 24, 2019.

  1. kr_vs

    kr_vs

    Joined:
    Mar 14, 2015
    Posts:
    6
    Hello. Seems like i can use treeview only through uxml, but cant access it from code. Any possibility to display my tree without writing own boilerplate?
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    TreeView was not ready for the release of UIElements and has been kept internal for now. We are working on making it a public API. For now, you cannot use it from code.
     
    vincismurf likes this.
  3. taylank

    taylank

    Joined:
    Nov 3, 2012
    Posts:
    182
    Any update or ETA on this?
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    No ETA at this time. My best suggestion, if you need it now, is to copy it from our source repo:
    https://github.com/Unity-Technologi...aster/Modules/UIElements/Controls/TreeView.cs

    You may need to also have a local implementation of ListView as TreeView uses some internal functions from ListView - but you can also use reflection for those. At least this way, you should be relatively ok when TreeView comes out as you'll just need to switch namespaces and fix the odd API change.

    Another option is to use an IMGUIContainer with IMGUI TreeView running inside.
     
  5. AndrewKaninchen

    AndrewKaninchen

    Joined:
    Oct 30, 2016
    Posts:
    149
    Is there still no ETA for this?
     
  6. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Still no ETA, I'm afraid. Though should be in by the time we release, which is now looking like Unity 2020.2.

    That said, the plan is to move UIElements to a package in 2020.1, which means full source access, which means TreeView will be a single `internal -> public` source change to use. You can also just copy it and remove some of the other internal calls inside from here:
    https://github.com/Unity-Technologi...aster/Modules/UIElements/Controls/TreeView.cs
     
  7. rigidbuddy

    rigidbuddy

    Joined:
    Feb 25, 2014
    Posts:
    39
    You could access any internal API (without reflection) by mimicking as friend assembly with asmdef
    1) Pick the name of "friend assembly" from InternalsVisibleTo arguments
    https://github.com/Unity-Technologies/UnityCsReference/search?q=internalsvisibleto
    ie "UnityEngine.Cloud" if you don't plan to use build it with cloud
    2) Make asmdef with that name
    ie UnityEngine.Cloud.asmdef
    3) Access any internal API from assembly under that asmdef

    But beware to not rely on internal API - it's subject to change
     
    Last edited: Feb 13, 2020
    net8floz likes this.
  8. R1PFake

    R1PFake

    Joined:
    Aug 7, 2015
    Posts:
    540
    The link doesn't work anymore, is the source still available somewhere?
     
  9. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
  10. AndrewKaninchen

    AndrewKaninchen

    Joined:
    Oct 30, 2016
    Posts:
    149
    Is this going to be internal forever?
     
  11. dpeter99

    dpeter99

    Joined:
    Sep 29, 2013
    Posts:
    7
    Any update on this? Could we maybe get it set to public but with an annotation that says it is not finialize yet? I would be more happy to change my code a few times to follow the changes than to always copy the whole thing than spend a lot of time fixing up all the internal stuff.
     
    Protagonist likes this.
  12. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    698
    Unfortunately making API public is not as simple as it sounds! Unfortunately the TreeView is not yet public at this moment but all I can say is it's actively being worked on :)
     
  13. Stacklucker

    Stacklucker

    Joined:
    Jan 23, 2015
    Posts:
    82
    I understand it takes time to polish these things, any updates though? :)
     
  14. martinpa_unity

    martinpa_unity

    Unity Technologies

    Joined:
    Oct 18, 2017
    Posts:
    479
    There will be a public TreeView control available in 2022.1.
     
  15. najati

    najati

    Joined:
    Oct 23, 2017
    Posts:
    42
    Sounds like that means that anyone sticking with 2021 to get on an LTS release won't have access to it, even for internal tools. Is that the case? Any chance of it being backported?
     
  16. Catsoft-Studios

    Catsoft-Studios

    Joined:
    Jan 15, 2011
    Posts:
    702
    I've finally had some time to play with the TreeView element. Although there's little documentation, it's pretty easy to use once you wrap the head around the fact that it's basically a "ListView".

    The only thing I'm missing (for now) is the possibility of being able to determine whether to accept a drop operation at a specific position.

    With IMGUI there is a boolean method that determines that. @uDamian (or any other) just tagging in case this is something that went off the radar or check if it will be added soon. Btw thanks for opening the API!
     
  17. aybe

    aybe

    Joined:
    Feb 20, 2019
    Posts:
    55
    @uDamian
    @JuliaP_Unity
    @martinpa_unity

    Do you guys have any hints on how to implement a search field such as an IMGUI's TreeView?

    The starting point I guess would be to have a custom controller but then comes the pain as pretty much everything is non-public, you have to re-implement this and this and this and so on...

    And well... the control isn't exactly bug-free, i.e. if you happen to click on an empty tree, you get a nice NRE :D

    Thanks :)
     
  18. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,498
    I wish there was a way to get this back to prior versions. 2022 LTS is a very long time to wait for a TreeView but I see from the source that it is quite dug in.

    Does anyone have any other solutions that might work in the meantime?
     
  19. unity_LRAc4SsAGnvbgw

    unity_LRAc4SsAGnvbgw

    Joined:
    Jun 25, 2023
    Posts:
    4
    Hi! I'm relatively new to Unity. Is there no way to use TreeView from an older version of Unity? Thanks!