Godot 4.41 .net: Can't seem to create trimesh collision using c# import script (from tutemic tutorial)

Godot Version

4.41

Question

Hi,
I’m trying to convert the tutemic tutorial’s reimport script that creates trimesh collision nodes on an imported glb file. Since I’m trying to stay in c#, this was my first approach:

using Godot;
using System;

[Tool]
public partial class ScenePostImport : EditorScenePostImport
{
    public override GodotObject _PostImport(Node scene)
    {
        GD.Print("postimport starting");
        try
        {
            RecursiveCreateCollision(scene);
            GD.Print("trying recursivecreate collision");
        }
        catch (Exception ex)
        {
            GD.PrintErr($"Error during post import: {ex.Message}\n{ex.StackTrace}");
        }
        GD.Print("returning scene");
        return scene;
    }

    private void RecursiveCreateCollision(Node node)
    {
        GD.Print("recursive create collision starting...");
        try
        {
            if (node is MeshInstance3D meshInstance && meshInstance.Mesh != null)
            {
                meshInstance.CreateTrimeshCollision();
                GD.Print("trying create trimesh collision");
            }

            foreach (Node child in node.GetChildren())
            {
                GD.Print("recursion child node");
                RecursiveCreateCollision(child);
            }
        }
        catch (Exception ex)
        {
            GD.PrintErr($"Error processing node {node.Name}: {ex.Message}");
        }
    }
}

And it doesn’t even seem to run. So I tried a gdscript version:

@tool
extends EditorScenePostImport

func _post_import(scene: Node) -> Object:
	recursive_create_collision(scene)
	print("returning scene")
	return scene
	
func recursive_create_collision(object: Node) -> void:
	if object is MeshInstance3D:
		print("is meshinstance 3d")
		object.create_trimesh_collision()
	else: print("bad mesh")
	
	for child in object.get_children():
			print("for child part")
			recursive_create_collision(child)


This does run and it does create collision but I cannot see them in the scene graph which I find really odd. (also I only see the prints when I specifically click reimport, not on drag into scene.)

Any insight as to why the C# doesn’t work and why i’m not seeing the created collision nodes in the scene graph would be great! Thanks!

No idea why the C# version didn’t work.

CollisionShapes you set on import, whether through the script or the Advanced import feature are not visible. Likely this is due to the fact that you cannot edit them once they are imported.

Yeah I didn’t know about the Edit Children option, but it still didn’t help me figure out the C# issues, ah well.

Editable Children will not solve your problem. They are locked on importing. The only way to change them is through an import script.