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

Resolved How to add Callbacks for VisualElement style parameters?

Discussion in 'UI Toolkit' started by skelitheprogrammer, Feb 13, 2023.

  1. skelitheprogrammer

    skelitheprogrammer

    Joined:
    Sep 20, 2019
    Posts:
    14
    Is there any way to register callbacks for style parameters such as Display; Opacity for basic VisualElement?

    something like element.RegisterCallback<ChangeEvent<DisplayStyle>>(Callback)

    Can't understand is there a way or maybe I'm doing something wrong
     
  2. martinpa_unity

    martinpa_unity

    Unity Technologies

    Joined:
    Oct 18, 2017
    Posts:
    370
    Hi @skelitheprogrammer!
    There are no events currently when the inline or resolved styles change. You would need to manually track changes for the time being.
     
  3. skelitheprogrammer

    skelitheprogrammer

    Joined:
    Sep 20, 2019
    Posts:
    14
    Hello, thanks for the answer! Is it possible to do with the UI Toolkit C# API or I need to create a workaround?
     
  4. martinpa_unity

    martinpa_unity

    Unity Technologies

    Joined:
    Oct 18, 2017
    Posts:
    370
    If you need to track changes to specific properties, such as the display, you would need to cache it somewhere and then compare it, there is nothing publicly available at the moment to track changes on style properties. You can cache them from
    element.resolvedStyle
    .
     
  5. skelitheprogrammer

    skelitheprogrammer

    Joined:
    Sep 20, 2019
    Posts:
    14
    Thank you for the anwser!