rayxuln/spine-runtime-for-godot

Problems setting/creating skins at runtime?

jonchun opened this issue · 6 comments

Using the following resources:
http://esotericsoftware.com/spine-examples-mix-and-match

The following code does not do what I expect:

spine_sprite.get_skeleton().set_skin_by_name("default")
spine_sprite.get_skeleton().set_skin_by_name("hair/brown")

I expect to see brown hair, but instead it shows nothing/blank (default skin)

If I do

spine_sprite.get_skeleton().set_skin_by_name("hair/brown")

then I see brown hair. It seems that once I set_skin_by_name, I can't do it again?


I then tried to build a skin from scratch

var custom_skin: SpineSkin = SpineSkin.new()
var hair = spine_sprite.get_skeleton().get_data().find_skin("hair/brown")
custom_skin.add_skin(hair)

However, the 3rd line (add_skin method) freezes Godot at this point when I try to execute it. I don't get any errors or anything.

What DOES seem to work is doing the following:

# need to set a skin first otherwise get_skin() returns null
spine_sprite.get_skeleton().set_skin_by_name("default")
var custom_skin: SpineSkin = spine_sprite.get_skeleton().get_skin()
var hair: SpineSkin = spine_sprite.get_skeleton().get_data().find_skin("hair/brown")
custom_skin.add_skin(hair)
spine_sprite.get_skeleton().set_skin(custom_skin)

With the above code, I'm able to add_skin() fine without Godot freezing. However, set_skin() doesn't seem to do anything (similar to how trying to set_skin_by_name() didn't seem to do anything after you've already set the skin once)

This is in custom built Godot 3.2.2-stable using the current master branch of spine-runtime-for-godot.
macOS Mojave 10.14.6

CustomSkinProject.zip

I've set up and uploaded a demo project for ease of testing

Tagging @scottkunkel because of comment in EsotericSoftware/spine-runtimes#728

custom skins cannot be initiated as empty skins atm; copying existing skin and adding more skins to it will work.

Nevermind. I'm just dumb. Needed to set_to_setup_pose()

spine_sprite.get_skeleton().set_skin_by_name("default")
var custom_skin: SpineSkin = spine_sprite.get_skeleton().get_skin()
var hair: SpineSkin = spine_sprite.get_skeleton().get_data().find_skin("hair/brown")
custom_skin.add_skin(hair)
spine_sprite.get_skeleton().set_skin(custom_skin)
spine_sprite.get_skeleton().set_to_setup_pose()

Closing this issue, but I think that there might be value in adding this example to the examples repo so others know how to achieve this.

I opened #11 to track this.

Skins are not working as intended.

while set_to_setup_pose() is required, in your last example you are actually adding brown hair to the default skin at runtime. The next time you call up default skin in the same scene, it has brown hair attached to it.

Instead, you should create a new skin and add default and brown hair to it, however that's currently broken.