Mitch




https://www.youtube.com/watch?v=W8BDM_jth3Y

Here be it! Features are now live on repo and the unity package.

<3 Pharan again
User avatar
Mitch

Mitch
Posts: 968

Nate

Very cool! :)
User avatar
Nate

Nate
Posts: 7977

davidsvson

@Mitch I love you so much! :)

Realized i needed to do exactly this. Everything is working just great!
davidsvson
Posts: 51

acorrow

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!
acorrow
Posts: 3

Mitch

slot.attachment = null
User avatar
Mitch

Mitch
Posts: 968

acorrow

Thanks Mitch! Occams razor much?

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

skeletonRenderer.skeleton.FindSlot(SlotName).SetToSetupPose();
acorrow
Posts: 3

davidsvson

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
GoblinWithDagger.jpg


Eye get squeezed when attached to animation
GoblinWithEye.jpg
davidsvson
Posts: 51

Mitch



not seeing the same issue :( sorry.
User avatar
Mitch

Mitch
Posts: 968

davidsvson

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!
davidsvson
Posts: 51

Mitch

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
User avatar
Mitch

Mitch
Posts: 968

francordoba

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?
Attachments
error_spine.jpg
francordoba
Posts: 9

Mitch

Drag prefab into scene, set properties, hit apply.
User avatar
Mitch

Mitch
Posts: 968

francordoba

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

Mitch

You only have to drag it once?

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

Mitch
Posts: 968

francordoba

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.
francordoba
Posts: 9

mistergreen

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

Pharan

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
User avatar
Pharan

Pharan
Posts: 4954


Return to Unity