i’m using gdscript to generate a mesh, and i’d like that mesh to have a trimesh static collision body. it’s easy for me to do this in the editor, by pressing the Mesh>Create Trimesh Static Body button. but what i want is to be able to update this collision shape at the same time, when i generate the mesh. that way i don’t have to re set up my collider with it’s collision layer mask etc.
seems like it should be trivial to do this in gdscript since there is an editor button for it, but the collisionshape3d node takes a resource called a Shape3D, and what i have is a mesh. can i make a Shape3D out of a mesh? what’s the best way for me to update a collisionshape from gdscript using a mesh?
So you would need access to your mesh in the script and call one of these functions to get the Shape and then apply that shape to the collisionshape. Using create_trimesh_shape would be my first pick. I wonder if I can use this for my own game.
okay actually i’m having a strange issue with this now. it works perfectly in the editor when i’m using my @tool script to set the collision shape to the mesh (i can see that the collision shape fits the form by making collision shapes visible) but when i actually play the game the collisionshape’s shape reverts to what it was before i used the @tool script. there’s nothing in my code that is setting the shape except for in that tool script which i am turning off to play the game, so there must be something in godot resetting or not saving the shape? the visual mesh does update correctly in game, just not the collider