rayxuln / spine-runtime-for-godot

This project is a module for godot that allows it to load/play Spine skeleton animation.
MIT License
93 stars 22 forks source link

Problems setting/creating skins at runtime? #10

Closed jonchun closed 4 years ago

jonchun commented 4 years ago

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)

jonchun commented 4 years ago

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

jonchun commented 4 years ago

CustomSkinProject.zip

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

jonchun commented 4 years ago

Tagging @scottkunkel because of comment in https://github.com/EsotericSoftware/spine-runtimes/issues/728

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

jonchun commented 4 years ago

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()
jonchun commented 4 years ago

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.

scottkunkel commented 4 years ago

I opened https://github.com/rayxuln/spine-runtime-for-godot/issues/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.