• Unity
  • Can I Change attachment color?

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.

Related Discussions
...
1年 後

@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.

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.

Thanks Pharan, will keep it in mind.

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

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

4日 後

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

2年 後

I try this and doesn't work at all. is there any way to change skin color using similar tech?

I just tried the following code successfully:

var slot = skeletonAnimation.Skeleton.FindSlot(slotName);
slot.SetColor(new Color(1, 0, 0, 1));

If you don't see any effect, please check the script update order as described above. Your script shall run after SkeletonAnimation and SkeletonRenderer. If this is already the case, please post the code you are using to set the color.

  • pppr がこの投稿に返信しました。
    1年 後

    Hello - i have this issue marked in another post. We do not currently have a fix for it. We use what's above. Can you have a look when there is time?

    We have included two video examples and a 2 line code snippet to explain what we are doing. Our game's in Open Beta right now on Steam.
    http://esotericsoftware.com/forum/Slot-SetColor-Not-working-properly-for-some-users-15290

    I have answered to the mentioned thread. In general there is no need to post references to other thread's postings, we will find all new ones.

    4年 後

    Harald
    Is it possible to change specific slot color of SkeletonGraphic(UI)?
    I tried same method, but didn't happen anything.

    SkeletonGraphic character;
    Skeleton skeleton = character.Skeleton;
    skeleton.FindSlot("hair").SetColor(Color.red);
    • Misaki がこの投稿に返信しました。

      pppr It is possible to change the color of the slots even when using the `SkeletonGraphic' component, and the code you tried does not seem to be wrong. To clarify, the following code should produce the results you see in the following video:

      public class SetSlotColor : MonoBehaviour
      {
          public SkeletonGraphic skeletonGraphic;
          
          void Start()
          {
              skeletonGraphic.Skeleton.FindSlot("head").SetColor(Color.red);
          }
      }

      You may want to show us your entire code regarding your skeleton.

      • pppr がこの投稿に返信しました。

        Misaki
        It works now! Thanks a lot!

        • Misaki が「いいね」しました。