Search Unity

My VisualElement and OnGeometryChange

Discussion in 'UI Toolkit' started by TashaSkyUpchurch, Jan 27, 2021.

  1. TashaSkyUpchurch

    TashaSkyUpchurch

    Joined:
    Jan 25, 2018
    Posts:
    13
    So I have TokenMenu, which is a VisualElement. It is in my UXML that I am using for the UI for a game I'm making. On TokenMeny(VisualElement) I have defined via UXML that there is a Slider.

    So as far as I could decode. The design pattern is to register value changed events on children in the callback of OnGeometryChange. like this:


    Code (CSharp):
    1.  public TokenMenu()
    2.         {
    3.             this.RegisterCallback<GeometryChangedEvent>(OnGeometryChange);
    4.             this.RegisterCallback<ClickEvent>(OnAttachToPanel);
    5.            
    6.         }
    This worked. Until it did not. Now every time OnGeometryChange comes up, there are not any children.

    It might have happened after I upgraded the unity version my project was using. It might be something else.

    Regardless I need a better way to have things happen in unity when my user interacts with the UI any help would be appreciated! :)
     
  2. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    572
    This pattern should work as it is used by the TwoPaneSplitView. I would need more information to see what could go wrong.

    But if you are just interested in the valueChangedEvent you could register the callback on the parent and let the propagation happen until you catch it there. Would that be simpler for you?