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. Dismiss Notice

Question Appear animation?

Discussion in 'UI Toolkit' started by dthurn, Sep 25, 2022.

  1. dthurn

    dthurn

    Joined:
    Feb 17, 2015
    Posts:
    77
    It is possible for a VisualElement to transition from one IStyle state to another using transition properties. However, I have not been able to figure an obvious way to make an element animate its initial appearance on-screen, for example to fade-in when first displayed or animate its position coming up from the bottom.

    Is there a way to accomplish this?
     
  2. ontrigger

    ontrigger

    Joined:
    Oct 31, 2016
    Posts:
    24
    You can do
    Code (CSharp):
    1. myElement.RegisterCallback<AttachToPanelEvent>(e =>
    2. {
    3.     myElement.AddToClassList("class-with-appear-transition");
    4. });
    If that doesn't work, you can use the GeometryChangedEvent instead. Note that this event can be called for a variety of other reasons.
     
  3. tattyd

    tattyd

    Joined:
    Feb 17, 2020
    Posts:
    14
    This still has the issue where you need to set up the element in it's hidden state in the UI Builder, so when it loads it can then immediately be shown. Which is obviously non-ideal.

    The only other solution I can think of is to, in code:

    - set transition time to 0
    - apply hidden styling
    - set transition time back to whatever it was before
    - apply visible styling

    Which seems like a hack...