- Uređeno
Unity Null reference with FindSlot and Attachment
Hi!
I'm running into a Null Reference when I try to get the attachments of a slot from a skeleton when running into a mobile device. Do you guys know if I need to initialize (or wait for) something before attempting to find the slot and its attachment?
My skeleton has several slots and I use this line to get the attachment
Attachment currentSlotOff = MyAsset.Skeleton.FindSlot(SlotName + "Off").Attachment;
Attachment currentSlotOn = MyAsset.Skeleton.FindSlot(SlotName + "On").Attachment;
I'm using C# in unity and a SkeletonGraphic.
Steps
- I have the SkeletonGraphic already on the screen.
- When initializingthe asset that uses this skeleton, I try to get the slot and the attachement
- I get a null reference, but only on the mobile build never on Unity's Editor
Thank you for your help!
From where are you calling the above line of code?
Is your SkeletonGraphic
GameObject perhaps instantiated via code or loaded dynamically in another way?
Hi Herald, nope, the skeleton is already in the scene, with an idle animation (this doesn't change) and Starting loop option ticked
We solved it!!! :greatsuccess:
So... we were trying to use the slot before Spine finished the initilialization,
we used the
SkeletonGraphic.Initialize(false);
to wait until this was done and then make use of them.
Glad you figured it out! Thanks for letting us know.