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

Bug UIToolkit StyleAnimation issue transition property references non-set value

Discussion in 'UI Toolkit' started by BlackclawsK, Mar 24, 2022.

  1. BlackclawsK

    BlackclawsK

    Joined:
    Jan 9, 2019
    Posts:
    100
    So we're seeing some weird issues, mostly on device (they are hard to trigger in editor)

    It seems to have to do with the Style Animation system as that is what the stack trace gives us and it might be that an animation is triggered twice as seems to run into Dictionary key duplication:

    System.ArgumentException: An item with the same key has already been added. Key: UnityEngine.UIElements.StylePropertyAnimationSystem+ElementPropertyPair
    at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x001cc] in <06a8633d56964cb4a0c4050a8ba5ed74>:0
    at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <06a8633d56964cb4a0c4050a8ba5ed74>:0
    at UnityEngine.UIElements.StylePropertyAnimationSystem+AnimationDataSet`2[TTimingData,TStyleData].Add (UnityEngine.UIElements.VisualElement owner, UnityEngine.UIElements.StyleSheets.StylePropertyId prop, TTimingData timingData, TStyleData styleData) [0x00066] in /home/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/StylePropertyAnimationSystem.cs:112
    at UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].UpdateProgress (System.Int64 currentTimeMs) [0x000ae] in /home/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/StylePropertyAnimationSystem.cs:811
    at UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].Update (System.Int64 currentTimeMs) [0x00008] in /home/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/StylePropertyAnimationSystem.cs:756
    at UnityEngine.UIElements.StylePropertyAnimationSystem.Update () [0x0001d] in /home/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/StylePropertyAnimationSystem.cs:1431
    at UnityEngine.UIElements.VisualElementAnimationSystem.Update () [0x000b1] in /home/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/VisualTreeAnimationUpdater.cs:87
    at UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) [0x0001e] in /home/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/VisualTreeUpdater.cs:111
    at UnityEngine.UIElements.Panel.UpdateAnimations () [0x0000d] in /home/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/Panel.cs:957
    at UnityEngine.UIElements.BaseVisualElementPanel.Update () [0x0001b] in /home/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/Panel.cs:561
    at UnityEngine.UIElements.RuntimePanel.Update () [0x0001d] in /home/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/GameObjects/RuntimePanel.cs:47
    at UnityEngine.UIElements.UIElementsRuntimeUtility.UpdateRuntimePanels () [0x0001d] in /home/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/UIElementsRuntimeUtility.cs:218
    at UnityEngine.UIElements.UIElementsRuntimeUtilityNative.UpdateRuntimePanels () [0x00001] in /home/bokken/buildslave/unity/build/Modules/UIElementsNative/UIElementsUtility.bindings.cs:26

    How do we debug this or rather, is this a bug that should be cought by UIToolkit itself? Its _really_ hard to reproduce reliably in Editor. This error also doesn't go away, its stuck in this state perpetually it seems and UIToolkit is partially non-functional afterwards.
     
  2. BlackclawsK

    BlackclawsK

    Joined:
    Jan 9, 2019
    Posts:
    100
    Managed a minimal repro that is consistent, it happens when you click a button that dismisses itself and the screen behind it but behind the button is another button that has a hover effect.

    Its complicated. I'll make sure to open a bug for this. Its _really_ weird.
     
  3. BlackclawsK

    BlackclawsK

    Joined:
    Jan 9, 2019
    Posts:
    100
    Ok after three hours of debugging this I now managed to cook it down to a minimal example and have submitted a bug report https://fogbugz.unity3d.com/default.asp?1413513:

    It seems this is an issue that is related to a transition style definition that references a non set property such as:

    .miau-button {
    transition: background-color 250ms;
    }

    Where background-color is not set. This leads to a continuous stream of exceptions following a NullReferenceException on removal of an item that is not the top of its respective hierarchy.
     
  4. BlackclawsK

    BlackclawsK

    Joined:
    Jan 9, 2019
    Posts:
    100
    Fun fact, this also only seems to happen if you _add_ a VisualElement to the same hierarchy you are removing the one that contains the transition in _the same frame_!
     
  5. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    62
    Did you end up working around this? I think I have the same issue. Only in 2022.1.17 but not 2021 LTS
     
  6. BlackclawsK

    BlackclawsK

    Joined:
    Jan 9, 2019
    Posts:
    100
    Yes, basically make sure you aren't doing it. Or if you _want_ to do it make sure to delay by one frame if you added something in the same frame.
     
  7. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    HI, I met the same problem in Unity 2022.2.1f1. Is this issue fixed? Or I should always take care of the removing?
     
  8. btsn

    btsn

    Joined:
    May 12, 2017
    Posts:
    40
    I've managed to hit it a couple of times in 2022.2.1. I can't confirm it's for the same reason, though.
     
  9. johfirefly

    johfirefly

    Joined:
    Aug 21, 2018
    Posts:
    14
    I also encounter this error in 2022.2.1f1
    In my case, the error randomly appears when you click on the GameObject (on which the UI Document is attached) in the scene hierarchy
    but... As far as I can tell this doesn't affect functionality... Just spamming bugs
     
  10. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    733
    We fixed
    We fixed the issue in the latest Unity stream, I am asking for a backport in 2022.2.
     
    btsn and johfirefly like this.
  11. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    62
    This would be great -- it's difficult to work around.
     
  12. OBiwer

    OBiwer

    Joined:
    Aug 2, 2022
    Posts:
    61
    Same error appearing in 2022.2.1f1 for me, since I've added this code:


    Code (CSharp):
    1.             InventoryNotification.schedule.Execute(
    2.                 () => {
    3.                     var x = InventoryNotification.style.scale.value.value.x;
    4.                     x = Mathf.Clamp(x, 0.9f, 1.1f);
    5.                     InventoryNotification.style.scale = new Scale(new Vector2(1 + (1 - x), 1 + (1 - x)));
    6.                 })
    7.                 .Every(1000);
    and in the style:

    Code (CSharp):
    1.  
    2. ... { ...
    3.     scale: 1 1;
    4.     transition-property: scale;
    5. }
    6.  
    error starts spamming after leaving the playmode. stops spamming only after domain reload. which makes working with it a real pain.


    it is preceeded by this two errors:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.UIElements.VisualElement.UpdateCallbackParentCategories () (at <469e18a818964f39910fa06bef052d82>:0)
    3. UnityEngine.UIElements.VisualElement.get_eventCallbackParentCategories () (at <469e18a818964f39910fa06bef052d82>:0)
    4. UnityEngine.UIElements.VisualElement.HasParentEventCallbacksOrDefaultActions (UnityEngine.UIElements.EventCategory eventCategory) (at <469e18a818964f39910fa06bef052d82>:0)
    5. UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].SendTransitionCancelEvent (UnityEngine.UIElements.VisualElement ve, System.Int32 runningIndex, System.Int64 panelElapsedMs) (at <469e18a818964f39910fa06bef052d82>:0)
    6. UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].CancelAllAnimations (UnityEngine.UIElements.VisualElement ve) (at <469e18a818964f39910fa06bef052d82>:0)
    7. UnityEngine.UIElements.StylePropertyAnimationSystem.CancelAllAnimations (UnityEngine.UIElements.VisualElement owner) (at <469e18a818964f39910fa06bef052d82>:0)
    8. UnityEngine.UIElements.VisualElement.UnityEngine.UIElements.IStylePropertyAnimations.CancelAllAnimations () (at <469e18a818964f39910fa06bef052d82>:0)
    9. UnityEngine.UIElements.VisualElement.UnregisterRunningAnimations () (at <469e18a818964f39910fa06bef052d82>:0)
    10. UnityEngine.UIElements.VisualElement.WillChangePanel (UnityEngine.UIElements.BaseVisualElementPanel destinationPanel) (at <469e18a818964f39910fa06bef052d82>:0)
    11. UnityEngine.UIElements.VisualElement.SetPanel (UnityEngine.UIElements.BaseVisualElementPanel p) (at <469e18a818964f39910fa06bef052d82>:0)
    12. UnityEngine.UIElements.VisualElement+Hierarchy.SetParent (UnityEngine.UIElements.VisualElement value) (at <469e18a818964f39910fa06bef052d82>:0)
    13. UnityEngine.UIElements.VisualElement+Hierarchy.RemoveAt (System.Int32 index) (at <469e18a818964f39910fa06bef052d82>:0)
    14. UnityEngine.UIElements.VisualElement+Hierarchy.Remove (UnityEngine.UIElements.VisualElement child) (at <469e18a818964f39910fa06bef052d82>:0)
    15. UnityEngine.UIElements.VisualElement.RemoveFromHierarchy () (at <469e18a818964f39910fa06bef052d82>:0)
    16. UnityEngine.UIElements.UIDocumentList.RemoveFromListAndFromVisualTree (UnityEngine.UIElements.UIDocument uiDocument) (at <469e18a818964f39910fa06bef052d82>:0)
    17. UnityEngine.UIElements.PanelSettings.DetachUIDocument (UnityEngine.UIElements.UIDocument uiDocument) (at <469e18a818964f39910fa06bef052d82>:0)
    18. UnityEngine.UIElements.UIDocument.RemoveFromHierarchy () (at <469e18a818964f39910fa06bef052d82>:0)
    19. UnityEngine.UIElements.UIDocument.OnDisable () (at <469e18a818964f39910fa06bef052d82>:0)
    20.  
    21.  
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.UIElements.VisualElement.UpdateCallbackParentCategories () (at <469e18a818964f39910fa06bef052d82>:0)
    3. UnityEngine.UIElements.VisualElement.get_eventCallbackParentCategories () (at <469e18a818964f39910fa06bef052d82>:0)
    4. UnityEngine.UIElements.VisualElement.HasParentEventCallbacksOrDefaultActions (UnityEngine.UIElements.EventCategory eventCategory) (at <469e18a818964f39910fa06bef052d82>:0)
    5. UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].QueueTransitionEndEvent (UnityEngine.UIElements.VisualElement ve, System.Int32 runningIndex) (at <469e18a818964f39910fa06bef052d82>:0)
    6. UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].UpdateProgress (System.Int64 currentTimeMs) (at <469e18a818964f39910fa06bef052d82>:0)
    7. UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].Update (System.Int64 currentTimeMs) (at <469e18a818964f39910fa06bef052d82>:0)
    8. UnityEngine.UIElements.StylePropertyAnimationSystem.Update () (at <469e18a818964f39910fa06bef052d82>:0)
    9. UnityEngine.UIElements.VisualElementAnimationSystem.Update () (at <469e18a818964f39910fa06bef052d82>:0)
    10. UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <469e18a818964f39910fa06bef052d82>:0)
    11. UnityEngine.UIElements.Panel.UpdateAnimations () (at <469e18a818964f39910fa06bef052d82>:0)
    12. UnityEngine.UIElements.BaseVisualElementPanel.Update () (at <469e18a818964f39910fa06bef052d82>:0)
    13. UnityEngine.UIElements.RuntimePanel.Update () (at <469e18a818964f39910fa06bef052d82>:0)
    14. UnityEngine.UIElements.UIElementsRuntimeUtility.UpdateRuntimePanels () (at <469e18a818964f39910fa06bef052d82>:0)
    15. UnityEngine.UIElements.UIElementsRuntimeUtilityNative.UpdateRuntimePanels () (at <469e18a818964f39910fa06bef052d82>:0)
    16.  
    and then the error itself:
    Code (CSharp):
    1. ArgumentException: An item with the same key has already been added. Key: UnityEngine.UIElements.StylePropertyAnimationSystem+ElementPropertyPair
    2. System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <8f06425e63004caf99a79845675f751e>:0)
    3. System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <8f06425e63004caf99a79845675f751e>:0)
    4. UnityEngine.UIElements.StylePropertyAnimationSystem+AnimationDataSet`2[TTimingData,TStyleData].Add (UnityEngine.UIElements.VisualElement owner, UnityEngine.UIElements.StyleSheets.StylePropertyId prop, TTimingData timingData, TStyleData styleData) (at <469e18a818964f39910fa06bef052d82>:0)
    5. UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].UpdateProgress (System.Int64 currentTimeMs) (at <469e18a818964f39910fa06bef052d82>:0)
    6. UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].Update (System.Int64 currentTimeMs) (at <469e18a818964f39910fa06bef052d82>:0)
    7. UnityEngine.UIElements.StylePropertyAnimationSystem.Update () (at <469e18a818964f39910fa06bef052d82>:0)
    8. UnityEngine.UIElements.VisualElementAnimationSystem.Update () (at <469e18a818964f39910fa06bef052d82>:0)
    9. UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <469e18a818964f39910fa06bef052d82>:0)
    10. UnityEngine.UIElements.Panel.UpdateAnimations () (at <469e18a818964f39910fa06bef052d82>:0)
    11. UnityEngine.UIElements.BaseVisualElementPanel.Update () (at <469e18a818964f39910fa06bef052d82>:0)
    12. UnityEngine.UIElements.RuntimePanel.Update () (at <469e18a818964f39910fa06bef052d82>:0)
    13. UnityEngine.UIElements.UIElementsRuntimeUtility.UpdateRuntimePanels () (at <469e18a818964f39910fa06bef052d82>:0)
    14. UnityEngine.UIElements.UIElementsRuntimeUtilityNative.UpdateRuntimePanels () (at <469e18a818964f39910fa06bef052d82>:0)
    15.  
     
    Last edited: Feb 6, 2023
  13. OBiwer

    OBiwer

    Joined:
    Aug 2, 2022
    Posts:
    61
    could fix it:

    this throws the exception:
    Code (CSharp):
    1. .foo {
    2.     transition-property: scale;
    3.     transition-duration: 1s;
    4.     scale: 0.9 0.9;
    5. }
    6.  
    7. .foo.enlarge {
    8.     scale: 1.1 1.1;
    9. }
    10.  
    this does not:
    Code (CSharp):
    1. .foo {
    2.     scale: 0.9 0.9;
    3.     transition-property: scale;
    4.     transition-duration: 1s;
    5. }
    6.  
    7. .foo.enlarge {
    8.     scale: 1.1 1.1;
    9. }
    10.  
    also seemed to be related to: Unity Issue Tracker - [UIToolkit] ArgumentExceptions are thrown and spammed after transition with empty property (unity3d.com)
     
  14. spakment

    spakment

    Joined:
    Dec 19, 2017
    Posts:
    90
    this is still an issue in 2022.2.10
     
  15. ErnestSurys

    ErnestSurys

    Joined:
    Jan 18, 2018
    Posts:
    82
  16. bartuq

    bartuq

    Joined:
    Sep 26, 2016
    Posts:
    127
    I reported this bug. Since then 8 new versions have been released but it's still not fixed. I'm using 2022.2.3f1 and waiting for the new 2022.2 in which it will be fixed. I can't do more than one animation in a loop without it.
     
    Last edited: Mar 16, 2023
    Greexonn and OBiwer like this.
  17. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    62
    Please backport this! Still not fixed in 2022.2.11f1 which makes it so I can't use animations in most of my UI, when it worked in 2021.3. This is a major regression!
     
  18. spakment

    spakment

    Joined:
    Dec 19, 2017
    Posts:
    90
    I've filed a bug report too
    https://unity3d.atlassian.net/servicedesk/customer/portal/2/IN-35324
    It's now very tricky to move on with my current project, built with 2022 (specifically to be able to use features of UITK), I'm uncomfortable moving the project to 2023 and being in bug-limbo, I'm considering stripping out all the uss transitions and replacing with DoTween
     
  19. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    733
    Apologies, I bumped the request for a backport.
     
    Greexonn likes this.
  20. bartuq

    bartuq

    Joined:
    Sep 26, 2016
    Posts:
    127
    It seems like my issue reported as UUM-24716 is finally fixed in 2022.2.14 :) The issue is gone. Check out your projects too.

    2022.2.14
    • UI Toolkit: Fixed NullReferenceException followed by ArgumentException when removing an element from its panel during a style transition. (UUM-22564)
     
    spakment and Greexonn like this.
  21. spakment

    spakment

    Joined:
    Dec 19, 2017
    Posts:
    90
    tested and my issues are fixed in 2022.2.14 too :)