Search Unity

Bug Animation Transition

Discussion in 'UI Toolkit' started by Takeguro, Aug 21, 2022.

  1. Takeguro

    Takeguro

    Joined:
    Oct 8, 2010
    Posts:
    29
    Hi,
    I have some issue that I am starting to think is not my error. I load same scene with ui toolkit and it seems that if there is animation transition going on when load mouse button is clicked it throws null ref error and then proceeds to spam "item with same key has already been added" errors. This locks animated transitions for the life of game, updating ui manually still works. Disabling Ui Document while keeping custom script enabled makes it go away.

    Initial error:
    NullReferenceException: Object reference not set to an instance of an object
    UnityEngine.UIElements.VisualElement.get_nextParentWithEventCallback () (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.VisualElement.UpdateCallbackParentCategories () (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.VisualElement.get_eventCallbackParentCategories () (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.VisualElement.HasParentEventCallbacksOrDefaultActions (UnityEngine.UIElements.EventCategory eventCategory) (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].SendTransitionCancelEvent (UnityEngine.UIElements.VisualElement ve, System.Int32 runningIndex, System.Int64 panelElapsedMs) (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].CancelAllAnimations (UnityEngine.UIElements.VisualElement ve) (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.StylePropertyAnimationSystem.CancelAllAnimations (UnityEngine.UIElements.VisualElement owner) (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.VisualElement.UnityEngine.UIElements.IStylePropertyAnimations.CancelAllAnimations () (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.VisualElement.UnregisterRunningAnimations () (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.VisualElement.WillChangePanel (UnityEngine.UIElements.BaseVisualElementPanel destinationPanel) (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.VisualElement.SetPanel (UnityEngine.UIElements.BaseVisualElementPanel p) (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.VisualElement+Hierarchy.SetParent (UnityEngine.UIElements.VisualElement value) (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.VisualElement+Hierarchy.RemoveAt (System.Int32 index) (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.VisualElement+Hierarchy.Remove (UnityEngine.UIElements.VisualElement child) (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.VisualElement.RemoveFromHierarchy () (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.UIDocumentList.RemoveFromListAndFromVisualTree (UnityEngine.UIElements.UIDocument uiDocument) (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.PanelSettings.DetachUIDocument (UnityEngine.UIElements.UIDocument uiDocument) (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.UIDocument.RemoveFromHierarchy () (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
    UnityEngine.UIElements.UIDocument.OnDisable () (at <8c4c0c3614e7457984f7ec0d5dc10278>:0)
     
    ChickChuck2 likes this.
  2. Takeguro

    Takeguro

    Joined:
    Oct 8, 2010
    Posts:
    29
    Can reproduce now. 2 ui documents at same scene have transition. Loading scene during transition triggers errors. Waiting past the transition loads scene as it should.
    Deleting one ui document and then hitting play -> Loading scene during transition works without errors
     
  3. Neutron

    Neutron

    Joined:
    Apr 25, 2011
    Posts:
    45
    There are a ton of bugs with transitions. Two I remember are that changing the sort order of two panels together throws an exception, and that changing the sort order of a panel cancels any transitions on elements in it. Additionally transition events sometimes randomly (ie I haven't figured out the exact cause) don't fire.
     
    ontrigger likes this.
  4. Takeguro

    Takeguro

    Joined:
    Oct 8, 2010
    Posts:
    29
    Sending bug report. And great. Transitions are that buggy huh.. Now gotta drop them everywhere.
     
  5. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    Experiencing this as well. Additively loading a scene while an existing transition is going on will give exception at
    VisualElement.UpdateCallbackParentCategories()
    like in the OP. (Unity 2022.1)

    @Takeguro Any progress on your bug report?

    My current workaround is to set style.transitionProperty to null for any VEs with ongoing transitions before any call to load new scene.

    Setting style.transitionProperty to null doesn't seem to end the existing ongoing transitions... Tried setting StyleList<StylePropertyName> with StyleKeyword.None, and still no go.

    Anyone knows the proper way of explicitly stopping ongoing transitions?
     
    Last edited: Sep 29, 2022
    ChickChuck2 likes this.
  6. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    Okay I'm having some success with setting both
    property
    and
    duration
    to none and 0, and then wait a frame (and then additively load the scene).

    Are there better ways of stopping ongoing transitions?
     
  7. Takeguro

    Takeguro

    Joined:
    Oct 8, 2010
    Posts:
    29
    Ahaha.. I stopped caring about that the moment Neutron above mentioned that there are lots of problems with transitions. I only animate opacity so I do that manually in script.

    But I checked the report for you and it is at https://issuetracker.unity3d.com/is...-a-scene-with-ui-toolkit-animation-transition

    It is marked "Won't Fix". So yeah.. They also changed description a bit. I think I also wrote it stops all transitions from working for the lifetime of the game, loading a scene will not help. Only exiting the game and starting again fixes it. But whatever. Who needs that end game menu screen appearing anyway.

    As for workaround.. Use one UI Document. Looked like the bug does not show up then.
    Or maybe try beta. Maybe they fixed it there. I do not plan on returning to transitions so I do not know if it is fixed or not
    Or stop using transitions and animate them manually.
     
    Last edited: Sep 30, 2022
  8. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    @Takeguro Thanks for getting back to me! Strange that Unity replied with "Wontfix". At least in my mind, it should be the Engine's job to gracefully kill any ongoing transitions when loading new scenes. Hopefully, they'll re-evaluate this.

    UPDATE: Just tested in 2022.2b9 (latest beta right now). The bug is fixed (at least for my use case). :)
     
    Last edited: Feb 23, 2023
  9. Takeguro

    Takeguro

    Joined:
    Oct 8, 2010
    Posts:
    29
    Good to know. As for "wont fix", looking at the issuetracker page again, bug was not reproduced in 2023 alpha so possibly got fixed or something got changed and the issue vanished. So worst case scenario it would vanish in 2023 release.
     
    Singtaa likes this.
  10. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    572
    The bug has been classified as won't fix because it is already fixed in the 2022.2 and 2023.1 development branches. Normally the QA process would have to find exactly what pr did solve the issue to get the "resolved with" message, and it seems that in this case someone did take a shortcut as it was already fixed and there would be no actual difference other than the incomplete resolution message.
     
    Singtaa likes this.
  11. jakob-leitner

    jakob-leitner

    Joined:
    Nov 11, 2020
    Posts:
    18
    I just tested it in 2022.2.0b14 and it is still throwing the exception. :(
     
  12. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I tested in 2022.2.0b16 and it still exists.
     
  13. bartuq

    bartuq

    Joined:
    Sep 26, 2016
    Posts:
    127
    I also had issues with animation transition. My thread LINK
    Reordering UIDocuments solved my issue but now I have two documents with transitions and everything is back. It's frustrating. Unity 2022.2.1f1 and it still exists.
     
    Last edited: Dec 17, 2022
  14. ChickChuck2

    ChickChuck2

    Joined:
    Aug 5, 2019
    Posts:
    8
    are you disabled and enabling the gameobject?
     
  15. jakob-leitner

    jakob-leitner

    Joined:
    Nov 11, 2020
    Posts:
    18
  16. Denis-535

    Denis-535

    Joined:
    Jun 26, 2022
    Posts:
    34
    I still (2022.2.10f1) suffer from this bug.
    I just remove VisualElement with animation and I get an error.

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.UIElements.VisualElement.UpdateCallbackParentCategories () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    3. UnityEngine.UIElements.VisualElement.get_eventCallbackParentCategories () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    4. UnityEngine.UIElements.VisualElement.HasParentEventCallbacksOrDefaultActions (UnityEngine.UIElements.EventCategory eventCategory) (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    5. UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].QueueTransitionStartEvent (UnityEngine.UIElements.VisualElement ve, System.Int32 runningIndex) (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    6. UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].UpdateProgress (System.Int64 currentTimeMs) (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    7. UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].Update (System.Int64 currentTimeMs) (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    8. UnityEngine.UIElements.StylePropertyAnimationSystem.Update () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    9. UnityEngine.UIElements.VisualElementAnimationSystem.Update () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    10. UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    11. UnityEngine.UIElements.Panel.UpdateAnimations () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    12. UnityEngine.UIElements.BaseVisualElementPanel.Update () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    13. UnityEngine.UIElements.RuntimePanel.Update () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    14. UnityEngine.UIElements.UIElementsRuntimeUtility.UpdateRuntimePanels () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    15. UnityEngine.UIElements.UIElementsRuntimeUtilityNative.UpdateRuntimePanels () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
    @SimonDufour so, is it fixed or not?

    I found a workaround: Just first deactivate the root VisualElement and then activate it again.
    Code (CSharp):
    1.  
    2. Document.rootVisualElement.Remove( ScreenView );
    3. ScreenView.Remove( MyView );
    4. Document.rootVisualElement.Add( ScreenView );
    5.  
     
    Last edited: Mar 14, 2023
  17. jakob-leitner

    jakob-leitner

    Joined:
    Nov 11, 2020
    Posts:
    18
    @SimonDufour Has this issue been resolved? If yes in which version? :)
     
  18. jakob-leitner

    jakob-leitner

    Joined:
    Nov 11, 2020
    Posts:
    18
    For anyone coming across this error: I think it was fixed in 2022.2.14f1, 2023.1.0b11 and 2023.2.0a9.