• Runtimes
  • setAttachment to null when spine player load

I would like to remove an attachment when the player loads and assumed this would work, however the player does not update.

new SpinePlayer('spine-player', {
  success: function (player) {
    player.skeleton.setAttachment('back-attachment', null);
  },
  ...raptor.config,
});

The only way I can make it work is by adding a timeout function

new SpinePlayer('spine-player', {
  success: function (player) {
    setTimeout(() => {
      player.skeleton.setAttachment('back-attachment', null);
    }, 100);
  },
  ...raptor.config,
});

Is there a better way of doing this without the timeout?

Related Discussions
...

The success callback is called after the skeleton and atlas is loaded, but before Player.calculateAnimationViewport() is called, which in turn will call skeleton.setToSetupPose(). This will effectively change the attachment back to what it was.

You can instead use the frame() callback, which is called right before updating the animation state and skeleton, and set the attachment to null there. frame() is called every frame (d'oh), so you might only want to set things once. It's not a performance issue to set things each frame though.

  • julian đã trả lời bài viết này.
  • julian đã thích điều này.

    Mario Thanks for the quick response that's just what I was looking for!