Hi guys!
I was just wondering if its possible to change the skins of characters inside of Unity. If it is possible could you tell me how to do this?
For example when I press a button the outfit/weapon of a character will change
Hi guys!
I was just wondering if its possible to change the skins of characters inside of Unity. If it is possible could you tell me how to do this?
For example when I press a button the outfit/weapon of a character will change
a SkeletonAnimation
has a .skeleton
.
So you get your SkeletonAnimation and go skeletonAnimation.skeleton.SetSkin("nameofyourskin");
Oh I see... what About if I only want to change for example a weapon of the character?
There's a recently added component/MonoBehaviour in the Spine-Unity runtime called "CustomSkin".
Add it to your GameObject that has the SkeletonAnimation. This script will allow you to assign attachments through the inspector to "skin placeholders" you defined in the skeleton when you were rigging it in Spine.
You can also do this programmatically. You just need to follow the basic logic found inside the CustomSkin script.
It only has a Start method. It should be easy to understand. If there's something you don't understand about it, just post your questions here.
So you get your SkeletonAnimation and go skeletonAnimation.skeleton.SetSkin("nameofyourskin");
@Pharan, how do I actually "get" my SkeletonAnimation?
This is an old topic from two years ago and the information above may not be recommended or apply to the current runtimes.
You probably want to open a new topic if you're trying to find specific information.
Are you talking about in code? GetComponent<SkeletonAnimation>()
? Are you new to Unity?
Hello! Pharah, can you tell please how to change custom skin programmatically? So, I can set up targets slots and attachments in inspector and it works fine with Start(), but I need learn how to change it on other events.
I found how to call CustomSkin component (linked to spine character) from other object, but I have no idea what to write for changing target slot etc.
Thanks
Hello! I found solution, I just modified CustomSkin like that:
using UnityEngine;
using Spine;
using Spine.Unity;
public class PickClothes : MonoBehaviour {
private GameObject player;
[System.Serializable]
public class SkinPair
{
[SpineAttachment(currentSkinOnly: false, returnAttachmentPath: true, dataField: "skinSource")]
[UnityEngine.Serialization.FormerlySerializedAs("sourceAttachment")]
public string sourceAttachmentPath;
public string targetSlot;
public string targetAttachment;
}
SkeletonRenderer skeletonRenderer;
public Skin customSkin;
public SkinPair[] skinItems;
public SkeletonDataAsset skinSource;
void Start () {
player = GameObject.FindGameObjectWithTag("Player");
skeletonRenderer = player.GetComponentInChildren<SkeletonRenderer>();
customSkin = new Skin("CustomSkin");
}
void OnMouseDown()
{
Skeleton skeleton = skeletonRenderer.skeleton;
foreach (var pair in skinItems)
{
var attachment = SpineAttachment.GetAttachment(pair.sourceAttachmentPath, skinSource);
customSkin.AddAttachment(skeleton.FindSlotIndex(pair.targetSlot), pair.targetAttachment, attachment);
}
skeleton.SetSkin(customSkin);
}
}
and now I can put this script to some another object, set up skin source and manually write target slot & target attachment and it works, skin part changed when clicking object. The reason I need to rewrite custom skin array is error "Must have reference to a SkeletonDataAsset" when this script put to another object