Null exception in RigBuilder when timeline previewing spawned object.

Hi,
I am using Rig Builder v1.1.1 with Unity 2021.3.6f1
Here is the error code:

[10:25:20] NullReferenceException: Object reference not set to an instance of an object
      UnityEngine.Animations.Rigging.RigBuilder.BuildPreviewGraph(UnityEngine.Playables.PlayableGraph graphUnityEngine.Playables.Playable inputPlayable) [Library/PackageCache/com.unity.animation.rigging@1.1.1/Runtime/AnimationRig/RigBuilder.cs:197]
      UnityEngine.Timeline.AnimationTrack.CreateMixerPlayableGraph(UnityEngine.Playables.PlayableGraph graphUnityEngine.GameObject goUnityEngine.Timeline.IntervalTree`1[UnityEngine.Timeline.RuntimeElement] tree) [Library/PackageCache/com.unity.timeline@1.6.4/Runtime/Animation/AnimationTrack.cs:644]
      UnityEngine.Timeline.TrackAsset.CreatePlayableGraph(UnityEngine.Playables.PlayableGraph graphUnityEngine.GameObject goUnityEngine.Timeline.IntervalTree`1[UnityEngine.Timeline.RuntimeElement] treeUnityEngine.Playables.Playable timelinePlayable) [Library/PackageCache/com.unity.timeline@1.6.4/Runtime/TrackAsset.cs:781]
      UnityEngine.Timeline.TimelinePlayable.CreateTrackPlayable(UnityEngine.Playables.PlayableGraph graphUnityEngine.Playables.Playable timelinePlayableUnityEngine.Timeline.TrackAsset trackUnityEngine.GameObject goSystem.Boolean createOutputs) [Library/PackageCache/com.unity.timeline@1.6.4/Runtime/TimelinePlayable.cs:202]
      UnityEngine.Timeline.TimelinePlayable.CompileTrackList(UnityEngine.Playables.PlayableGraph graphUnityEngine.Playables.Playable timelinePlayableSystem.Collections.Generic.IEnumerable`1[UnityEngine.Timeline.TrackAsset] tracksUnityEngine.GameObject goSystem.Boolean createOutputs) [Library/PackageCache/com.unity.timeline@1.6.4/Runtime/TimelinePlayable.cs:135]
      UnityEngine.Timeline.TimelinePlayable.Compile(UnityEngine.Playables.PlayableGraph graphUnityEngine.Playables.Playable timelinePlayableSystem.Collections.Generic.IEnumerable`1[UnityEngine.Timeline.TrackAsset] tracksUnityEngine.GameObject goSystem.Boolean autoRebalanceSystem.Boolean createOutputs) [Library/PackageCache/com.unity.timeline@1.6.4/Runtime/TimelinePlayable.cs:115]

I have a custom TimelineAsset with custom tracks.
One of the things I do is spawn objects/characters in preview and animate them so that I can have a better preview of what it will look like in game

I assume the error happens because I preview the object before it has time to Initialize.

I was wondering if it was safe to replace the RigBuilder script with a custom one? The problematic function is not virtual so I cannot override it. So I would need to make a compltely seperate script to replace it.
Is there any complication I could run into if I do that?

I haven’t checked future versions to see if the issue persists because Updating is not an option at this point in time.

Thank you for your time.

Upgarding to Animation Rigging v1.2.1 seems to fix the error mentioned above.

But I’m getting another issue now about a memory leak.
I assume that’s caused by me destroying the object with the animator when I stop the preview.
I assume I have to cleanup something before I destroy the animated object. But I don’t know what.

Any pointers would be really appriciated

A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeArray`1:.ctor(Int32, Allocator, NativeArrayOptions)
UnityEngine.Animations.Rigging.PropertySyncer:Create(Int32) (at Library\PackageCache\com.unity.animation.rigging@1.2.1\Runtime\AnimationJobs\RigSyncSceneToStreamJob.cs:65)
UnityEngine.Animations.Rigging.RigSyncSceneToStreamJobBinder`1:Create(Animator, RigSyncSceneToStreamData&, Component) (at Library\PackageCache\com.unity.animation.rigging@1.2.1\Runtime\AnimationJobs\RigSyncSceneToStreamJob.cs:183)
UnityEngine.Animations.Rigging.AnimationJobBinder`2:UnityEngine.Animations.Rigging.IAnimationJobBinder.Create(Animator, IAnimationJobData, Component) (at Library\PackageCache\com.unity.animation.rigging@1.2.1\Runtime\AnimationJobs\IAnimationJobBinder.cs:72)
UnityEngine.Animations.Rigging.SyncSceneToStreamLayer:Initialize(Animator, IList`1) (at Library\PackageCache\com.unity.animation.rigging@1.2.1\Runtime\AnimationRig\SyncSceneToStreamLayer.cs:25)
UnityEngine.Animations.Rigging.RigBuilderUtils:BuildPlayables(Animator, PlayableGraph, IList`1, SyncSceneToStreamLayer) (at Library\PackageCache\com.unity.animation.rigging@1.2.1\Runtime\AnimationRig\RigBuilderUtils.cs:58)
UnityEngine.Animations.Rigging.RigBuilder:BuildPreviewGraph(PlayableGraph, Playable) (at Library\PackageCache\com.unity.animation.rigging@1.2.1\Runtime\AnimationRig\RigBuilder.cs:279)
UnityEngine.Timeline.AnimationTrack:CreateMixerPlayableGraph(PlayableGraph, GameObject, IntervalTree`1) (at Library\PackageCache\com.unity.timeline@1.6.4\Runtime\Animation\AnimationTrack.cs:644)
UnityEngine.Timeline.TrackAsset:CreatePlayableGraph(PlayableGraph, GameObject, IntervalTree`1, Playable) (at Library\PackageCache\com.unity.timeline@1.6.4\Runtime\TrackAsset.cs:781)
UnityEngine.Timeline.TimelinePlayable:CreateTrackPlayable(PlayableGraph, Playable, TrackAsset, GameObject, Boolean) (at Library\PackageCache\com.unity.timeline@1.6.4\Runtime\TimelinePlayable.cs:202)
UnityEngine.Timeline.TimelinePlayable:CompileTrackList(PlayableGraph, Playable, IEnumerable`1, GameObject, Boolean) (at Library\PackageCache\com.unity.timeline@1.6.4\Runtime\TimelinePlayable.cs:135)
UnityEngine.Timeline.TimelinePlayable:Compile(PlayableGraph, Playable, IEnumerable`1, GameObject, Boolean, Boolean) (at Library\PackageCache\com.unity.timeline@1.6.4\Runtime\TimelinePlayable.cs:115)