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

Bug USS Animation only works on one element in a list?

Discussion in 'UI Toolkit' started by justpassingby, Dec 24, 2022.

  1. justpassingby

    justpassingby

    Joined:
    Jun 7, 2016
    Posts:
    2
    Hello, I have recently started experimenting with UIToolkit animations and I've run into a problem when trying to animate several elements at once. I have a handful of labels that only differ in their text value that are stored in a list. I want to them to fade out at the same time. To do that, I tried the following:

    Code (CSharp):
    1.         private void FadeOutOptions(ClickEvent evt)
    2.         {
    3.             foreach (var option in _MenuOptions)
    4.             {
    5.                 option.AddToClassList("hide");
    6.             }
    7.         }
    When I run the code, what happens is only the first label in the list fades out. The rest of them jump from 100 -> 0 opacity once the animation for the first label finishes. Why doesn't this work?
     
  2. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    It depends on what is in your uss. If you are going to hide all the elements, you can assign the hide class to their parent and style them with .parentclass.hide > .elementclass, that way you don't need to foreach any longer.
     
    justpassingby likes this.
  3. justpassingby

    justpassingby

    Joined:
    Jun 7, 2016
    Posts:
    2
    @dlorre This worked well. Thank you!
     
    dlorre likes this.