From d1749f8aa8732bfc60a2d9b31a4aa1be0ab8872f Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 6 Jul 2021 12:12:52 +0200 Subject: [PATCH] [unity] Fixed potential null reference exception upon access in Start if `Reload Scene` is disabled. Closes #1919. --- .../Runtime/spine-unity/Components/SkeletonAnimation.cs | 8 +++++++- .../Runtime/spine-unity/Components/SkeletonGraphic.cs | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs index 315f9e37e..48c4ec713 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs @@ -52,7 +52,12 @@ namespace Spine.Unity { /// /// This is the Spine.AnimationState object of this SkeletonAnimation. You can control animations through it. /// Note that this object, like .skeleton, is not guaranteed to exist in Awake. Do all accesses and caching to it in Start - public Spine.AnimationState AnimationState { get { return this.state; } } + public Spine.AnimationState AnimationState { + get { + Initialize(false); + return this.state; + } + } private bool wasUpdatedAfterInit = true; #endregion @@ -105,6 +110,7 @@ namespace Spine.Unity { } } set { + Initialize(false); if (_animationName == value) { TrackEntry entry = state.GetCurrent(0); if (entry != null && entry.loop == loop) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs index 366054a6e..5dddee360 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs @@ -377,7 +377,12 @@ namespace Spine.Unity { public event SkeletonRendererDelegate OnMeshAndMaterialsUpdated; protected Spine.AnimationState state; - public Spine.AnimationState AnimationState { get { return state; } } + public Spine.AnimationState AnimationState { + get { + Initialize(false); + return state; + } + } [SerializeField] protected Spine.Unity.MeshGenerator meshGenerator = new MeshGenerator(); public Spine.Unity.MeshGenerator MeshGenerator { get { return this.meshGenerator; } }