TobyWils

I'm having an issue switch skins. A constraint from one skin is affecting another skin. The constraint is definitely assigned to the correct skin and not the other, and switching between skins in the Spine editor works correctly but not in the game.

I'm wonder if I'm not switching skins correctly. I'm doing...
_skeleton->setSkin(nullptr); // Clear old skin. Not sure if this is needed.
_skeleton->setSkin(skin_name);
_skeleton->setSlotsToSetupPose();
_animation_state->apply(*_skeleton);
Using Spin 3.8.99 and the latest cpp runtimes.
TobyWils
  • 記事: 20

Nate

You don't need to set the skin to null.

Skeleton setSkin calls updateCache, which is what sets constraints active or not:
https://github.com/EsotericSoftware/spine-runtimes/blob/3.8/spine-cpp/spine-cpp/src/spine/Skeleton.cpp#L332

You could debug and make sure your constraint is set to not active. Or, you could check if it is active before and after calling setSkin.

Do you see the problem if you use Skeleton Viewer? That can help us determine if the problem is in all runtimes or only spine-cpp.
アバター
Nate

Nate
  • 記事: 11351

TobyWils

Some information:
  • The constraint exists in one skin but not in the other
  • In the preview view, the constraint disappears and reappears correctly when switching between skins
  • in-game, the constraint remains active when switching between skins - which we just confirmed with a debug trace
  • Is there anything we could be doing differently when switching between skins at run-time?
TobyWils
  • 記事: 20

Nate

Calling setSkin is enough. You can debug by breakpointing the sort constraint methods when you call setSkin, eg:
https://github.com/EsotericSoftware/spine-runtimes/blob/3.8/spine-cpp/spine-cpp/src/spine/Skeleton.cpp#L609

The idea is to find out how constraint->_active can possibly be true for the constraint you expect to have it be false.
アバター
Nate

Nate
  • 記事: 11351

TobyWils

I tried tracing into the cpp code but without a good upstanding of the internals and what I'm looking for it's going to be impossible to find the problem. One thing I did do is load the spine file into a quick and simple Unity project, switched skins and they work fine, so Unity works and the cpp code is broken.
TobyWils
  • 記事: 20

Nate

If you want to try again, breakpoint on line 609 that I showed above. When that is run for the constraint with the problem, why is constraint->_active set to true? In other words, what are the 4 boolean values on that line?
constraint->_active = constraint->_target->_active && (!constraint->_data.isSkinRequired() || (_skin && _skin->_constraints.contains(&constraint->_data)));
  • constraint->_target->_active is true if the contraint's target bone is active (meaning it is not a skin bone, or it is a skin bone and the current skin has the target bone). This could be true or false, depending on your skeleton and the current skin. When you call setSkin it calls updateCache which sets the bones to active or not.
  • constraint->_data.isSkinRequired() is true if this constraint is in a skin. I expect this to be true, since you said the constraint is in a skin.
  • _skin evaluates to true if a skin is set. Make sure it is the skin you expect (eg look at the skin name).
  • _skin->_constraints.contains(&constraint->_data))) is true if the current skin contains the constraint. I expect this to be false, since you said you've set a skin that does not have the constraint.

With the values I expect above, constraint->_active would be assigned false. Since you say it is true, we need to know the values above so we know why it gets true.
アバター
Nate

Nate
  • 記事: 11351


Return to Runtimes