- Uređeno
Can I Change attachment color?
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.
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.
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
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?
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.
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
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
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.
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.
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.