• Runtimes
  • [UNITY] Getting amount of attachments via Script possible?

Hi there,

I am setting attachments via script in Unity and I want to choose a random attachment from all possible attachments in a slot. Since the available attachments are not always the same amount, I need a way to get the amount of attachments in any given slot via Script. Is this possible? I haven't found a command that will give me this number.

Thanks!

Related Discussions
...
  • Modificato

skeletonAnimation.Skeleton.Skin.FindAttachmentsForSlot(index, list)

Mitch ha scritto

skeletonAnimation.Skeleton.Skin.FindAttachmentsForSlot(index, list)

Thanks, but I can't get it to work, somehow. This is part of my code:

foreach (Spine.Slot slot in skel.slots) {

   List<Attachment> attachmentList = new List<Attachment>();

   int slotIndex = skel.FindSlotIndex(slot.data.name);
   skel.skin.FindAttachmentsForSlot(slotIndex, attachmentList);
}

The goal is to iterate through each slot of the skeleton, then find each attachment. But this gives me an exception:

NullReferenceException: Object reference not set to an instance of an object

What am I doing wrong? How can I access the List generated by the FindAttachmentsForSlot() Method ?

Err yea.... thanks Spine runtime...

if your skin is null, that means its using the default skin.

skeletonAnimation.Skeleton.Data.DefaultSkin

use that one.

Mitch ha scritto

Err yea.... thanks Spine runtime...

if your skin is null, that means its using the default skin.

skeletonAnimation.Skeleton.Data.DefaultSkin

use that one.

Awesome! Thank you so much, I was going a bit crazy because the bug made no sense 😛

Thanks for your help! :heart: