I have a character with attachments.
Then I have two skins, and each contain a single attach to change the weapon on the character.
I can swap the skin once, but if I try to swap to the second skin it doesn't work.
After the first swap, the second one takes no effect.
On code I'm doing
var custom_skin = get_node("%SpineSpriteHuman").new_skin(weapon.id)
var data = get_node("%SpineSpriteHuman").get_skeleton().get_data()
custom_skin.add_skin(data.find_skin("weapons/" + weapon.id))
get_node("%SpineSpriteHuman").get_skeleton().set_skin(custom_skin)
Is this the correct way to do this?
Another related question, I don't have a "base" skin.
Right now I am doing weapons, but later on I will want to also add "armor" so if I'm showing "weapon1" and "armor1", but later on I want to switch to "weapon1" and "armor2", am I doing this correctly or do I need some sort of base skin to be able to do this.
I would think I would need to do something like "get current skin> find current slot > remove attachment from this slot and add a different one".
Alternatively I thought I would do as the example code above, create a new skin every time I need to swap a weapon or armor, add "weapon1" and "armor2" to it and do set_skin, but as reported above, that is not working for me (hopefully I'm just not doing something right).
Do you have sample code for this?
I see now that the "base" skin is called "default"
I have
print("output of get_skins ", get_node("%SpineSpriteHuman").get_skeleton().get_data().get_skins())
for skin in get_node("%SpineSpriteHuman").get_skeleton().get_data().get_skins():
print("skin names ", skin.get_name())
print("skin_name before swapping ", get_node("%SpineSpriteHuman").get_skeleton().get_skin().get_name())
print("weapon_id ", weapon.id)
var data = get_node("%SpineSpriteHuman").get_skeleton().get_data()
var custom_skin = get_node("%SpineSpriteHuman").new_skin(weapon.id)
custom_skin.remove_attachment(0,"weapon")
custom_skin.add_skin(data.find_skin("default"))
custom_skin.add_skin(data.find_skin("weapons/" + weapon.id))
get_node("%SpineSpriteHuman").get_skeleton().set_skin(custom_skin)
print("skin_name after swapping ", get_node("%SpineSpriteHuman").get_skeleton().get_skin().get_name())
and this outputs:
output of get_skins [[SpineSkin:38277], [SpineSkin:38278], [SpineSkin:38279]]
skin names default
skin names weapons/dagger
skin names weapons/flail
skin_name before swapping flail
weapon_id dagger
skin_name after swapping dagger
So the skins are swapping, as I mentioned the first swap makes visual changes, but the second one doesn't change the visuals.
Is there something I need to reset before changing the skin?
This started working when I added one more line at the end:
After the set_skin if I add "set_slots_to_setup_pose()" then the visuals change to what I expect.
My current code with this working:
var data = get_node("%SpineSpriteHuman").get_skeleton().get_data()
var custom_skin = get_node("%SpineSpriteHuman").new_skin(weapon.id)
custom_skin.add_skin(data.find_skin("default"))
custom_skin.add_skin(data.find_skin("weapons/" + weapon.id))
get_node("%SpineSpriteHuman").get_skeleton().set_skin(custom_skin)
get_node("%SpineSpriteHuman").get_skeleton().set_slots_to_setup_pose()
I would still like to know if this is expected, if I'm supposed to call the "set_slots_to_setup_pose".
I will later try adding from different skins, like I said, a "weapons" and "armor" skin to see if all is working.