Is it possible to bind a method call or Action to a button element

Hi,

I was wondering if it is possible to bind a method call or Action to a button element.

Imagine the following:

<UXML xmlns:ui="UnityEngine.UIElements" xmlns:ue="UnityEditor.UIElements">
  <ui:VisualElement class="toolbar">
    <ui:VisualElement class="toolbar-container">
      <Style path="Assets/Editor/Resources/ToolbarStyle.uss" />
      <ui:Label class="toolbar-element" text="Number of Blocks" />
      <ue:IntegerField class="toolbar-element integer" binding-path="NumberOfBlocks" />
      <ui:Button class="toolbar-element" text="Create Tower" binding-path="CreateTower" />
    </ui:VisualElement>
  </ui:VisualElement>
</UXML>

VisualElement with class ‘toolbar-container’ is bound to a class with a public int NumberOfBlocks and a static void CreateTower.

We don’t have any immediate plans to support action bindings in UXML but it’s something we’ll keep in mind as we work on a runtime-capable binding system for UIElements.

Bump. Has there been any progress on supporting this with the new releases? If it is supported already, where can I find docs?

Still not possible however we are working on a data bindings solution as we speak. I can’t guarantee we will have event/action/callback bindings too but I’m adding your voice to the requests already made. Happy Holidays!

1 Like