[unity] Fixed potential null reference exception upon access in Start if Reload Scene is disabled. Closes #1919.

This commit is contained in:
Harald Csaszar 2021-07-06 12:12:52 +02:00
parent 52ecc9349c
commit d1749f8aa8
2 changed files with 13 additions and 2 deletions

View File

@ -52,7 +52,12 @@ namespace Spine.Unity {
/// <summary>
/// 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</summary>
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)

View File

@ -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; } }