I understand you're experiencing NullReferenceException errors in the SkeletonGraphic.ApplyAnimation() method that you cannot reproduce locally. This is affecting about 5% of your users on Kindle Fire devices.
Based on the stack traces and the fact that this happens within the Spine library itself, here are several potential causes and solutions:
Potential Causes
The issue likely stems from accessing SkeletonGraphic.skeleton or modifying active attachments after SkeletonGraphic.LateUpdate() has been called. This timing issue can cause the internal state to become inconsistent, leading to null references during the next frame's update cycle.
Recommended Solutions
Ensure Proper Initialization
Make sure the SkeletonGraphic is fully initialized before accessing its properties:
void Start() {
skeletonGraphic.Initialize(false);
// Now safe to access skeletonGraphic.Skeleton, AnimationState, etc.
}
Check Timing of Skeleton Modifications
If you're modifying the skeleton, attachments, or animation state from your scripts, ensure you're not doing so after SkeletonGraphic.LateUpdate() has run. Use the provided callback delegates instead:
void Start() {
skeletonGraphic.UpdateComplete -= OnUpdateComplete;
skeletonGraphic.UpdateComplete += OnUpdateComplete;
}
void OnUpdateComplete(ISkeletonAnimation anim) {
// Safe to modify skeleton here
}
Add Null Checks in Your Code
Before accessing any Spine properties, verify they're not null:
if (skeletonGraphic != null &&
skeletonGraphic.AnimationState != null &&
skeletonGraphic.Skeleton != null) {
skeletonGraphic.AnimationState.SetAnimation(0, "animation", true);
}
Check Script Execution Order
Ensure your scripts that interact with SkeletonGraphic run at the appropriate time. You can adjust this in Unity via Edit -> Project Settings -> Script Execution Order.
Consider the Multiple Canvas Renderers Setting
Check if you have Advanced - Multiple Canvas Renderers enabled on your SkeletonGraphic component. This setting can sometimes cause issues. Try disabling it if enabled.
Verify SkeletonDataAsset Assignment
Make sure the Skeleton Data Asset is properly assigned at the SkeletonGraphic component in the Inspector and that it loads correctly at runtime. If you're using any delayed loading mechanisms (addressables, asset bundles), ensure the assets are fully loaded before initializing the skeleton.
Additional Debugging Steps
Since you can't reproduce this locally, consider adding defensive logging:
void Update() {
if (skeletonGraphic == null) {
Debug.LogError("SkeletonGraphic is null!");
return;
}
if (skeletonGraphic.Skeleton == null) {
Debug.LogError("SkeletonGraphic.Skeleton is null!");
return;
}
if (skeletonGraphic.AnimationState == null) {
Debug.LogError("SkeletonGraphic.AnimationState is null!");
return;
}
// Your animation code here
}
Low-End Device Considerations
For low-end devices like some Kindle Fire models, consider:
- Ensuring your app doesn't run out of memory
- Checking if the issue correlates with scene loads or heavy operations
- Verifying that your atlas textures and skeleton data are loading properly
If the issue persists after trying these solutions, you may want to send a minimal reproduction project (if you can create one) to contact@esotericsoftware.com for further investigation.