How to correctly swap the mesh of a MeshInstance when it's also parented to a Skeleton node?

minute_deltaminute_delta Posts: 2Member
edited April 12 in 3D

Hello,
I was trying to make a character editor with swappable wardrobe, but soon ran into a problem. As I'm still new to 3D and Godot in general, I'm definitely missing something here.

I have the following 3D model I quickly made, and then rigged and animated using Mixamo (for now it only has a single walking animation). It's body is divided into multiple parts like the Arms, Head, Legs and Torso.

I wanted to be able to change the "Torso" mesh into a "Vest" mesh during runtime with the press of a button, so I used the following code which has proven to work in a different test I did before (the code itself is assigned to the Torso's MeshInstance node):

 func _on_Button_pressed():
  # Load the new mesh
  var newMesh = load("res://Vest.obj")
  # Swap the mesh
  self.mesh = newMesh
  # Set the material
  set_surface_material(1, load("res://material2mat.material"))

But of course it wouldn't be that easy. When the button is pressed, the torso part just goes invisible.

If I instead try to swap the mesh using the Inspector, the same result can be seen:

So I would like to know what is it that I'm missing here or if there is another way to do this. In the end, my objetive is to make a game where the player is able swap through different clothes and armor, and for me to accomplish this without a too tedious workflow every time I want to add new wardrobe.

Thanks for your attention.


Tags :

Best Answer

  • GlyphTheWolfGlyphTheWolf Posts: 100
    Accepted Answer

    Hi,

    I also make project with changeable equipment.

    My approach is to create both, character and all available equipment in the same blender file (equipment is basically done the same as body parts and rigged for main character skeleton). Export that file (in my case to gltf2.0). Then when importing in Godot I select to save all meshes in separate files. When changing some part of body I just change mesh of that part to one saved by Godot during import and it works well for me.

    Important is to make all parts rigged to the same skeleton in blender (I'm using blender, not sure about workflow with other programs)

Answers

  • GlyphTheWolfGlyphTheWolf Posts: 100Member
    Accepted Answer

    Hi,

    I also make project with changeable equipment.

    My approach is to create both, character and all available equipment in the same blender file (equipment is basically done the same as body parts and rigged for main character skeleton). Export that file (in my case to gltf2.0). Then when importing in Godot I select to save all meshes in separate files. When changing some part of body I just change mesh of that part to one saved by Godot during import and it works well for me.

    Important is to make all parts rigged to the same skeleton in blender (I'm using blender, not sure about workflow with other programs)

  • minute_deltaminute_delta Posts: 2Member

    Hi, I did as you said by importing my gltf file using the "Import witht Separate Objects" preset (I might experiment later with the other presets to see if there's a more convenient one), and it works!

    So, thank you very much for your help! =) :3
    It took me a while to reply because I was busy trying to rig everything properly in blender, which proved to be troublesome and presenting of it's own set of issues. Considering how much I had to look up just to make this work I might as well create a tutorial one day.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file