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 UI Toolkit runtime UI animation

Discussion in 'UI Toolkit' started by optimise, Aug 25, 2022.

  1. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,046
    Currently seems like UI Toolkit runtime UI animation only have simple UI animation feature. Is there any ETA and plan to implement better and feature rich runtime UI animation and tooling that able to create complex animation? I would like to see tween animation tooling integrates into UI Toolkit runtime UI to enable high performance complex animation.
     
  2. achimmihca

    achimmihca

    Joined:
    Feb 13, 2016
    Posts:
    266
    What do you mean by "tween animation tooling"?

    In code, you can use LeanTween and similar libs (or plain coroutines) to interpolate from one value to another over time.
    Example:

    Code (CSharp):
    1.  LeanTween.value(gameObject, 0, 1, 0.3f) // Animate value from 0 to 1 in 0.3 seconds
    2.             .setOnUpdate((float interpolatedValue) => // This is called every frame
    3.             {
    4.                 visualElement.style.opacity = interpolatedValue;
    5.                 // Set other values as you please, scale, rotate, ...
    6.             })
    7.             .setOnComplete(() => visualElement.RemoveFromHierarchy()) // This is called when the animation is complete
    8.             .setEaseInSine(); // Use a nice (non-linear) curve for the interpolation
    9.  
    Of course, Unity could provide more advanced, visual animation tooling like Animator and friends that can record, save and replay arbitrary animations based on keyframes and state machines. I imagine that such a tooling is a must-have for non-coders.
    Is this planned? Or maybe could existing Unity tooling be re-used to animate VisualElements?
     
  3. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,046
    I expect something UI designer friendly visual editor like DOTween Pro but better than DOTween Pro so non-coder can create complex UI animation without involving programmer. You can say it's supercharged Animator that using tween way to do UI animation.
     
  4. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    328
    Hi optimise, that's a great question thanks for asking.

    You're correct, we decided to prioritize simple UI animations since it generally makes up most of animations found in UI, but we need to address the more complex scenarios.

    We're considering a few solutions, like providing CSS like animation features, supported by visual authoring workflows. Integration with the Timeline tool is another one, which would enable to orchestration of UI animations with other Scene objects.

    If you had to describe the best way for non-programmers to do UI animation, what would it look like?
     
    halivudestevez likes this.
  5. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,046
    Something like this but even better that it's a complete tooling without needing to involve any programmer. I expect even more integrated features that it will support Addressables by default out of the box and it will auto load and unload ui panels when out of camera screen.

     
    benoitd_unity likes this.
  6. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    328
    Ah yes, I'm in complete agreement. This is also something we'd like to provide in the future but we have so much to do before. Great feedback thank you!
     
    optimise likes this.
  7. jonas-thefullyarcade

    jonas-thefullyarcade

    Joined:
    May 9, 2019
    Posts:
    2
    Just a note for future me and others. If you use transitions in your USS, you can add classes to animate after X ms using this function:

    UiHelpers.cs
    Code (CSharp):
    1. public static class UiHelpers
    2.     {
    3.         public static void DelayAddToClassList(VisualElement ui, string classToAdd = "animate", int delay = 100)
    4.         {
    5.             ui.schedule.Execute(() => ui.AddToClassList(classToAdd)).StartingIn(delay);
    6.         }
    7.     }
    Usage in C#:
    Code (CSharp):
    1. UiHelpers.DelayAddToClassList(ui);
    And some transition declaration i USS:
    Code (USS):
    1. .button {
    2.     transition-property: translate opacity;
    3.     transition-timing-function: ease-out linear;
    4.     transition-duration: 0.3s 0.3s;
    5.     transition-delay: 0.2s 0.2s;
    6.     translate: -10 0;
    7.     opacity: 0;
    8. }
    9. .button.animate {
    10.     translate: 0 0;
    11.     opacity: 1;
    12. }
     
  8. seyfe

    seyfe

    Joined:
    May 10, 2019
    Posts:
    74
  9. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    279
    Imagine setting the position in this approach
    uiElement.style.translate = new StyleTranslate(new Translate(val, 0, 0));
    Here we have to create 2 new structs every update. not the optimized way of tweeting.
     
  10. Squeazer

    Squeazer

    Joined:
    Aug 4, 2015
    Posts:
    13
    I recently released a package that adds support to Timeline for animating UI Toolkit, you might find it useful: https://github.com/mihakrajnc/UITTimeline

    Still in early stages, currently supports transform, opacity, visibility, display, and adding / removing classes, but I'll be adding more styles and optimisations in the coming weeks.