2D skeleton parts swap

I wanted to ask how would I implement swappable body parts and clothes with 2D skeleton system.

Do I make the main skeleton bone system, separately 2d nodes with 2d polygons containing all the parts, weight paint them for the skeleton bones and then make them visible when needed? Or is there a better way to go about it? Something like a texture swapper?

Also how would I go about something like swappable wings with animations? Let’s say at one point the character grows wings they didn’t have before. Do I create a sprite/polygon with new bones and somehow attach it to the main body, or do I have to use a whole new body skeleton with wing bones (or make the first one with wing bones but not use them unless needed). Same would basically be creating a skirt that moves around.

Texture swapping on the parts should work, just access the body part (Polygon2D Node) and change the texture parameter to what you want, but if the body part shape needs to change per variant (where you place those polygons and UV’s on the Polygon2D Node), that would be a problem as the topology and shape are important to how it deforms with the skeleton among other things. So if say that one leg variant had a thicker boot than another, to get them to really deform well you’d need a different setup. Talking the Points and Polygons, where they are placed, how the points are weighted to the skeleton, etc.

If the amount of variations, at least shape wise, are decently limited, I’d do what you mentioned where you just add as many Polygon2D nodes for variants as you need, to the character scene, but then enable/disable them as needed (not just toggle their visibility). Then you’d get the ability to make that part variant work as best as it could with the same skeleton, and dialed in for deforming well, etc.

The more complex way is to somehow store all the data needed for that Polygon2D node FOR that body part variant in a resource of some kind, then just override those properties on the Polygon2D when the variant switches, but that could be hairy pretty quick.

Now, if the body part shapes are really generic, the texture swap method would be good, you’d just need a texture per body part per variant, and then just swap them in code as needed. You ‘could’ use a CanvasItemMaterial with a custom shader to do more fancy stuff with variants that would just be some simple things like color modifications and some basic transformations, but one thing that could be useful is getting the material to accept a ‘variant’ index and it’d use that in the material to pick a part from a texture where you have all of the variants laid out, like an atlas texture.

Thanks for the detailed response! The deform I think is not really necessary in my case since all the movable parts are separate (arm - forearm - hand etc.) so I could just make a bigger UV size to fit all the shapes, but I use one bigger image file with all the character parts/assets in there, not separate image files, so the UV location changes per item, which would I guess be an issue since I would somehow have to change the UV points anyway, which loops us back to making separate polygon/sprite nodes, unless I made them separate or an atlas or something? But that seems like a hassle, esp if I want to add more later on.

I think making polygon nodes with separate assets and call/enable/disable might be the easiest and most customizable way.

Outside of this, do you have any input on the wings part by the way? Is it possible to attach different bone skeletons together when needed (so like having a main body skeleton, and a separate wing skeleton, and somehow attach them together when needed so I can animate), or is it just better and easier to make a separate wing flapping animation and just show it playing on its own next to the main body when needed? So let’s say, I would have an animation for walk cycle, and a separate wing flapping animation, and I would just enable both of them in a scene, or only one if the wings are not there, essentially two skeletons next to each other, not connected. Or is it better to just make a whole new full animation set with and without the wings so like Walking animation and a different one Walking with Wings animation, completely separate.

Again, really appreciate the help!

1 Like

For the parts and their variants, it will probably come down to how flexible you want to be with mixing and matching different styles of parts, or if you could see having more set limitations to what you can change to at once. I say this as knowing and planning that would determine how you will setup your textures, to atlas or not to atlas, etc.

For how the textures are handled, if there are no set limitations and you can literally wear variant parts from a bunch of styles, one for each body part (or anything else), I would recommend just creating a single texture for each body part that can be interchanged. Then just make variants textures from then on, so you’d have Legs_V01, Legs_V02, etc, then just hot swap textures via code on that particular Polygon2D node when the player chooses what to wear.

If there are some set limitations for the player, or just in general there are not going to be many variants to worry about, I’d say set up an entire style set on one texture sheet, then make the other styles in the same way, just make sure the layout is the same, then for each Polygon2D body part you just hot swap in code the style texture on that particular part the player changes a variant on.

If you don’t have more complex setup needs for the Polygon2D nodes, like making the verts and polygons on the shape be specific to the texture sprite, or more detailed deformations. I could see where if you had a Polygon2D node for every variant part it could get to be more of a hassle and burden on the character setup/scene, and rely more on resources like textures, materials or custom resources (highly recommend using these as you could put a lot more gameplay info in the part resource, beyond just the texture you swap).

This gets complicated pretty fast :slight_smile:

For the wings, I could see just adding those bones to the existing skeleton, including the Polygon2D node and just doing the enable/disable trick again. This would lean into the idea of using the same Polygon2D body part nodes for all style variants as then you are more free to add specialy bones to the same skeleton, then just enable/disable the parts as needed.

On the animation side I don’t know if that could cause a problem if you play a non-walk cycle animation on a character where you enabled the wing parts, especially if that walk cycle animation didn’t include the wing bones when it was exported (and vice versa for that matter).

Thank you for all your help. This helped me realize many things and my plan how to tackle the issue and what approach might be the most optimal one for my needs. I’ll try and see how it goes. Really appreciate everything!

1 Like