Animation Transition

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+Values1[T].SendTransitionCancelEvent (UnityEngine.UIElements.VisualElement ve, System.Int32 runningIndex, System.Int64 panelElapsedMs) (at <8c4c0c3614e7457984f7ec0d5dc10278>:0) UnityEngine.UIElements.StylePropertyAnimationSystem+Values1[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)

1 Like

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

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.

1 Like

Sending bug report. And great. Transitions are that buggy huh… Now gotta drop them everywhere.

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 with StyleKeyword.None, and still no go.

Anyone knows the proper way of explicitly stopping ongoing transitions?

1 Like

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?

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 Unity Issue Tracker - NullReferenceException and ArgumentException appear in the Console when reopening 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.

@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). :slight_smile:

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.

1 Like

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.

1 Like

I just tested it in 2022.2.0b14 and it is still throwing the exception. :frowning:

I tested in 2022.2.0b16 and it still exists.

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.

are you disabled and enabling the gameobject?

@ChickChuck2 I am unloading the scene (:

I still (2022.2.10f1) suffer from this bug.
I just remove VisualElement with animation and I get an error.

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.UIElements.VisualElement.UpdateCallbackParentCategories () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
UnityEngine.UIElements.VisualElement.get_eventCallbackParentCategories () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
UnityEngine.UIElements.VisualElement.HasParentEventCallbacksOrDefaultActions (UnityEngine.UIElements.EventCategory eventCategory) (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].QueueTransitionStartEvent (UnityEngine.UIElements.VisualElement ve, System.Int32 runningIndex) (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].UpdateProgress (System.Int64 currentTimeMs) (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
UnityEngine.UIElements.StylePropertyAnimationSystem+Values`1[T].Update (System.Int64 currentTimeMs) (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
UnityEngine.UIElements.StylePropertyAnimationSystem.Update () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
UnityEngine.UIElements.VisualElementAnimationSystem.Update () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
UnityEngine.UIElements.Panel.UpdateAnimations () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
UnityEngine.UIElements.BaseVisualElementPanel.Update () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
UnityEngine.UIElements.RuntimePanel.Update () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
UnityEngine.UIElements.UIElementsRuntimeUtility.UpdateRuntimePanels () (at <55377d8dc0ee4d67989deb78b2b4baf8>:0)
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.

Document.rootVisualElement.Remove( ScreenView );
ScreenView.Remove( MyView );
Document.rootVisualElement.Add( ScreenView );

@SimonDufour Has this issue been resolved? If yes in which version? :slight_smile:

For anyone coming across this error: I think it was fixed in 2022.2.14f1, 2023.1.0b11 and 2023.2.0a9.