etri

Hello.

I need change my character's hair color in runtime.

There are many topics changing whole spine's material, but changing partial attachment.
I tried to use SpriteAttacher, but rectangle was appeared and many materials were attached.

How can I change specific attachment color?

Thanks.
etri
Posts: 2

Pharan

Each attachment object has r, g, b and a fields. Those are its color and it is shared across all skeletons that would use its color.

However, changing the color of the slot is recommended if you want to animate the color. Slot also has r, g, b and a.

Note that colors range from 0f to 1f as a float, not 0 to 255 as a byte.
User avatar
Pharan

Pharan
Posts: 4444

PixelBrothers

Hello etri,

If you want to change color for specific attachment color, you can simply by:
SkeletonAnimation.skeleton.FindSlot("slot name").SetColor(Color.red);
Let me know if you made it, if you can't figure out I will write a little example for you ;)
User avatar
PixelBrothers
Posts: 31

stephenanimation27

When I try to use SetColor it is giving me this error

Assets/Scripts/Units -Base/PlayerControl.cs(105,52): error CS1061: Type Spine.Skeleton' does not contain a definition for SetColor' and no extension method SetColor' of type Spine.Skeleton' could be found (are you missing a using directive or an assembly reference?)

do you know what I am doing wrong?
stephenanimation27
Posts: 15

Pharan

make sure you have the using directive
using Spine.Unity;
and are using the latest spine-unity. Though this is a pretty old feature. If all else fails, see my post above.
User avatar
Pharan

Pharan
Posts: 4444

IndieDoroid

@Pharan,

I can get the code to compile, but nothing happens. Is there something wrong in my code? I've got multiple skins on this character, is that affecting anything? :angel:
using Spine.Unity;

public class ChangeHairColor : MonoBehaviour {

[SerializeField] private SkeletonAnimator _skelAnim;

// Use this for initialization
void Start () {
_skelAnim = GetComponent<SkeletonAnimator> ();
}

// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Alpha6)){
_skelAnim.skeleton.FindSlot ("hair_attach").SetColor (Color.red);
}
}
[ UPDATE ] OK, it works if using SkeletonAnimation ... but I'm using SkeletonAnimator.
IndieDoroid
Posts: 8

Pharan

If you are also keying the color of that slot in the animation, you may need to make sure your code runs AFTER SkeletonAnimator's code.
The last to update always overrides all previous values.
User avatar
Pharan

Pharan
Posts: 4444

IndieDoroid

Thanks Pharan, will keep it in mind.

This morning magically that piece of code now works.. So problem solved? :rofl:
IndieDoroid
Posts: 8

Pharan

Unity can be pretty random about deciding which script should run first, so until you actually specify it in Unity's Script Execution Order settings, you may run into it magically working and not working in between Unity sessions. :p
User avatar
Pharan

Pharan
Posts: 4444

IndieDoroid

yes you're right. It's working on certain animations and not on others (idle animation) :x .. Will need to do a bit of research on the Execution Order thing you mentioned.
Thanks
IndieDoroid
Posts: 8


Return to Unity