Search Unity

Question UI Toolkit prefab for ui builder?

Discussion in 'UI Toolkit' started by Kamyker, Nov 15, 2022.

  1. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    It's nice that separation of logic/view/style is in UI Toolkit but for me far more important is separation of pieces of ui making it as modular as possible. I've seen the custom controls in docs https://docs.unity3d.com/Manual/UIB-structuring-ui-custom-elements.html but writing all the code seems like a downgrade compared to UGUI prefabs. I've tried to combine it with https://docs.unity3d.com/Manual/UIE-LoadingUXMLcsharp.html but it breaks UI Builder and prints errors after dropping the control https://forum.unity.com/threads/bug...ment-tree-from-uxml-unity-2021-2-6f1.1217169/

    In the end what I want is a simple ui element with:
    - structure defined in uxml
    - logic in cs script, uses structure from uxml
    - ability to drag-drop this element in UI Builder
    - (optional) default uss style for this element
     
  2. Jonathan-Westfall-8Bits

    Jonathan-Westfall-8Bits

    Joined:
    Sep 17, 2013
    Posts:
    271
    This might be a bit more possible starting in Unity 2023.1 Alpha 19.

    They added a new feature around Drag and Drop assets on your custom controls.
    You can create an object attribute in the UI Builder
    Due note not meaning GameObject, but closer to .net object so the more broad type.

    public UxmlAssetAttributeDescription<ScriptableObject> m_soData = new() { name = "so-data" }

    It can be any type of object for the most part.
    So mono behaviors, scriptable objects and so forth.
    The object you have can also have a custom inspector/drawer and it will be drawn inside of the UI Builder.
    So you can make a UXML Control, drag in your logic script, and in the control script call the object reference there by getting it's value from the UXML control and do whatever you want.

    Link here for more information.

    https://forum.unity.com/threads/new-feature-drag-and-drop-assets-on-your-custom-controls.1363195/
     
  3. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    Doesn't look like it. I want to define structure in UI Builder so UXML (like placing gameobjects for UGUI in prefab) not C#.

    Really weird that this very basic feature doesn't exist. Seems like a step backward from UGUI.
     
    Walter_Hulsebos likes this.