I'm using the skeletonGraphic component.
Trying to play the animation, an error occurs "NullReferenceException: Object reference not set to an instance of an object".
The animation fields contain animation references. There is a debug in the code - a control for an empty value.
Why does the error occur?
using Spine.Unity;
public class PlayerTopMenuController : MonoBehaviour
{
[SerializeField] private AnimationReferenceAsset addLiveAnimation, lostLiveAnimation;
private SkeletonGraphic skeletonGraphic;
void Start()
{
skeletonGraphic = GetComponent<SkeletonGraphic>();
PlayAnimations();
}
private void OnEnable()
{
GameActions.onPlayerLivesChanged += PlayAnimations;
}
private void Disable()
GameActions.onPlayerLivesChanged -= PlayAnimations;
}
private void PlayAnimations()
{
SetAnimation(addLiveAnimation, true, 1f);
}
public void SetAnimation(AnimationReferenceAsset animation, bool loop, float timeScale)
{
Debug.Log(animation.name);
if (animation==null) Debug.Log("Animation is null");
skeletonGraphic.AnimationState.SetAnimation(0, animation, loop); // NullReferenceException: Object reference not set to an instance of an object
}
}
PS
I tried to use the code from the theme
https://ru.esotericsoftware.com/forum/d/8090-skeletongraphic-animations-in-unity
and it didn't help.
GPT chat also could not find a solution.