Search Unity

Can you register a callback for when a list view child elements change?

Discussion in 'UI Toolkit' started by WizByteGames, May 1, 2020.

  1. WizByteGames

    WizByteGames

    Joined:
    Mar 28, 2013
    Posts:
    70
    I have a custom Visual Element where you have a list of popup fields that can be added and removed by pressing the add or remove button. Is there a way to tell the Visual Element that the child elements have changed?
     
  2. DonkeyPotato

    DonkeyPotato

    Joined:
    Mar 23, 2018
    Posts:
    28
  3. WizByteGames

    WizByteGames

    Joined:
    Mar 28, 2013
    Posts:
    70
    Maybe I didn't do a good enough job explaining what I want.

    So what I am trying to do is have a custom list of elements that can be dynamic. So basically you can add and remove items at will.

    I wanted to add buttons to the custom control that will add and remove items from the list.

    Since the added buttons will be apart of the custom control I wanted a way to tell if items were added or removed.

    I mean I know how to do it if the buttons are separate from the custom element, but I want to try and do it in a way where I can just have the buttons apart of the custom visual element.
     
  4. svobodajak

    svobodajak

    Joined:
    Jun 27, 2017
    Posts:
    11
    @WizByteGames I am trying to achieve something similar. Did you manage to somehow tell if the children of a VisualElement changed?
     
  5. WizByteGames

    WizByteGames

    Joined:
    Mar 28, 2013
    Posts:
    70
    The way I am currently doing it is to create a callback that runs every time I click the button to add or remove an item from the list. It requires adding an event/delegate but it gets the job done.
     
    svobodajak likes this.
  6. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231