Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Is there a callback for when an element is added to a UIDocument?

Discussion in 'UI Toolkit' started by Raccoonacoon, Sep 12, 2022.

  1. Raccoonacoon

    Raccoonacoon

    Joined:
    Dec 1, 2019
    Posts:
    4
    I need a means of determining when an item has been added to a UIDocument's panel, nondependent on hierarchy depth. I have tried registering an AttachToPanel callback to the visualTree of the UIDocument's rootVisualElement, but it is not getting called.

    My particular use case is localization. The UI I am developing is very dynamic, and I wish to scan all the text elements/controls/forms as they get added from a LocalizationManager and replace marked text fields with values queried from a localization table. If I can get a notification when a control has been added to the Document, then I can easily query it from the manager and apply localization.

    Is there any way of achieving this?
     
  2. Maverick

    Maverick

    Joined:
    Dec 18, 2009
    Posts:
    225
  3. Raccoonacoon

    Raccoonacoon

    Joined:
    Dec 1, 2019
    Posts:
    4
    I am currently doing this. I think the issue is that, according to my understanding, AttachToPanel is sent to child elements when they have been attached to a given panel. I need an event bubbling up to the panel itself to know when anything has been added or removed.
     
  4. seyfe

    seyfe

    Joined:
    May 10, 2019
    Posts:
    74
    I'd be interested in an answer to this question as well. How can a parent know that a child has been attached?