• Editor
  • setAttachment not working with 2DToolkit

Hi,

I am trying to create an attachment. Every thing works fine but setAttachment is not doing anything. It doesn't give any error also. It finds the slot and sets the attachment but i cant see it on my player.

Here is the code. I am instantiating prefab and setting skeleton data at run time.

GameObject playerGameObject = (GameObject)Instantiate (PlayerPrefab, Spawn.transform.position, Quaternion.identity);

string resourcePath = string.Format ("CharacterSkeletonData/{0}SkeletonData", characterName);
SkeletonDataAsset skeletonData = (SkeletonDataAsset)Resources.Load (resourcePath);

SkeletonAnimation skeletonAnim = playerGameObject.GetComponent<SkeletonAnimation> ();
skeletonAnim.skeletonDataAsset = skeletonData;

skeletonAnim.skeleton.SetAttachment ("Head", "Cap");


I tried setting attachment on already created game object with skeleton data but that also didn't work. Can anyone point me to right direction of how we can set an attachment in 2DToolKit?

Related Discussions
...

You said you are trying to create an attachment? Show the code for that? Or are you just trying to show an attachment that you have created in Spine?

SetAttachment would throw an exception if it couldn't find the attachment or slot. Maybe post your JSON.

What shader do you use?

Hey thanks for your quick response.

I am just trying to show an attachment which i created in Spine. I have attached the json.

I am using tk2d/BlendVertexColor shader. Which is 2DToolkits default shader for sprite collection.

Do i need to call setAttachment everytime i play an animation or its fine if i just call it once?

I was worried your shader was missing "Cull Off" and you were using negative non-uniform scale, but that isn't the case. The data looks good.

SpriteCollectionAttachmentLoader throws an exception if a region isn't in the atlas, so it must find your region. Maybe you use some TK2D atlas features that aren't supported by spine-tk2d's rendering? I don't think I can be of much more help unless you would like to send your Unity project: contact@esotericsoftware.com

Hi,

I resolved the issue. I am not sure what exactly worked but here are the things i did.

  • In Spine i had created a slot under a bone and drag dropped the image. Instead now i selected the image and set slot as parent.
  • I was using older version of 2DToolkit. So updated it to latest version also downloaded new Spine tk2d run time.

AND IT WORKED 🙂

Thanks Nate for your quick response and help. You are awesome guys building awesome product. :yes: