• Unity
  • [Unity]Attaching Unity Sprites to Skeletons

  • Đã chỉnh sửa
Related Discussions
...

Very cool! 🙂

17 ngày sau

@Mitch I love you so much! 🙂

Realized i needed to do exactly this. Everything is working just great!

Is there a way to REMOVE a sprite from code? I'm not seeing anything, but I likely missed something here. Any ideas? I basically want to attach a sprite, add an animation to the bone, and then remove it. Is this possible? Thanks!

slot.attachment = null

Thanks Mitch! Occams razor much?

I also solved this kind of on my own just now with this:

skeletonRenderer.skeleton.FindSlot(SlotName).SetToSetupPose();

8 ngày sau

What should i think about when i create the slots?

I'm experimenting with this but the sprites i attach usually show up rotated and/or deformed. 🙁


OK the rotation was just me forgetting to always check that the transform of the bone is always set to 0. But i can't figure out why the sprite attached show up stretched or squeezed. Any suggestions?


Something seems to be wrong with my sprites. I'm testing with the Spine Goblin example now and attach sprites to "left hand item" slot. Works great with the image from the goblin project. My own image gets squeezed 🙁

Animation looks good with dagger attached. Eye looks good

Eye get squeezed when attached to animation

 Loading Image

not seeing the same issue 🙁 sorry.

Thank you, it works as it should when I use sprites from the spine library, but not when I use my own sprites, what could possibly be wrong with my sprites?

I attach one of my sprites, when I attach it to the goblin it gets deformed.


Finally made it!

If I change the import settings of the sprite from Mesh Type: "Tight" to "full rect" instead. It works!

Ah Yea. I ignored that mode for a while as unity 4 cant do it. Unity 5 has sprite features that will make mesh sprite attachments viable

5 tháng sau

If I add the script to the instance on the hierarchy, work 100%, but if i add the script to the instance in the "prefab" in the folder, i have this problem...

  
using UnityEngine; using System.Collections; public class maniqui_scr : MonoBehaviour { public Sprite sprite; [SpineSlot] public string slot; void Start () { var skeletonRenderer = GetComponent<SkeletonRenderer>(); var anadido = skeletonRenderer.skeleton.AttachUnitySprite(slot, sprite); } }

"Must have reference to a SkeletonDataAsset".

Can anybody help me?

Drag prefab into scene, set properties, hit apply.

The problem is that my character is instantiated with code in the runtime...i dont drag the character...

You only have to drag it once?

The data is saved correctly even if it has an error message. Try it.

Thanks, everything works but now I see that the new sprite is not moving ...
Any suggestions?


Ok, I fixed the problem, I forgot to add a slot ... :notme:

Thank you for your attention.

2 năm sau

skeleton.AttachUnitySprite doesn't seem to exist in the latest runtime. What to use instead?

This is a pretty old topic.
The answer depends on what you need, as the old AttachUnitySprite isn't always ideal.

Many of the current tools are accessible if you add the following using to the top of your script:

using Spine.Unity.Modules.AttachmentTools;

To convert a Sprite to a one-off Attachment that you can use on your Skeleton, you can use:

Sprite yourSprite;
Material materialWithSettingsYouWant;
RegionAttachment newAttachment = yourSprite.ToRegionAttachment(materialWithSettingsYouWant);

To set it on the skeleton, you can call this:

Slot slot = skeleton.FindSlot("slot you want");
slot.Attachment = newAttachment;

If any animation or code is setting the slot attachment, it will overwrite the value you set, so you either need to remove other code that touches it, remove animation keys that touch it, or use slot.Attachment = newAttachment every frame after everything else. This was true even with the old AttachUnitySprite method.

Note that your Sprite's backing texture needs to have the correct import settings or it won't work.
https://github.com/pharan/spine-unity-docs/blob/master/img/spine-runtimes-guide/spine-unity/mixandmatch-texture-inspector-options.png