• Runtimes
  • Spine Flutter Custom Skin Animation Bounds

Hello! Please be gentle, I am new to Flutter and Spine Flutter.

If I intialise a character with a custom skin - I cannot seem to set the bounds.

`class SimpleAnimation extends StatelessWidget {
const SimpleAnimation({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {

reportLeaks();

var customSkin = Skin("custom-skin");
var data;
var skeleton;

final controller = SpineWidgetController(onInitialized: (controller) {

  data = controller.skeletonData;
  skeleton = controller.skeleton;

  customSkin.addSkin(data.findSkin("Skin1_cowgirl/Skin1_cowgirl_feet")!);
  customSkin.addSkin(data.findSkin("Skin1_cowgirl/Skin1_cowgirl_head")!);
  customSkin.addSkin(data.findSkin("Skin1_cowgirl/Skin1_cowgirl_lower body")!);
  customSkin.addSkin(data.findSkin("Skin1_cowgirl/Skin1_cowgirl_upper")!);

  skeleton.setSkin(customSkin);
  skeleton.setSlotsToSetupPose();

  controller.animationState.setAnimationByName(0, "animation", true);
});

return Scaffold(
    body: SpineWidget.fromAsset(
            "assets/StressTest2.atlas",
            "assets/stress_test2.json",
            controller,
            fit: BoxFit.contain,
            alignment: Alignment.center,
            boundsProvider: SkinAndAnimationBounds(skins: ["Skin1_cowgirl/Skin1_cowgirl_head","Skin1_cowgirl/Skin1_cowgirl_lower body"]),
          )
        );

}
}`

The above works if I select skin parts from the asset file.

But if I replace the boundsProvide to :

boundsProvider: SkinAndAnimationBounds(skins: ["custom-skin"])

I can't see my character. I'm assuming it's off-screen or zero height etc.

What am I doing wrong?

Related Discussions
...

The BoundsProvider is invoked before the controller's onInitialized callback.

The solution is to pass all the skins you use to create the custom skin in onInitialize to the bounds provider.

The other alternative is to write your own BoundsProvider, which does what your onInitialize does, and at the end invokes a SkinAndAnimationsBoundsProvider to return the bounds.

Thanks for pointing me in the right direction.

I'm normally pretty good at figuring stuff out through Google and experimentation, but when I google BoundsProvider - there are 4 results globally!

None explain how to write a BoundsProvider or pass skins to a BoundsProvider.

If you could provide a little more insight it would be appreciated.

Thank you 🙂

Never mind! I figured it out.