Generate Custom Mesh Collider dynamically + options for Rigid body

And, my code : (same than yours)

by user 224464722878005248

const instance = this.rightTooth

        var mesh: Mesh | null = null;              
        instance.traverse((x: Object3D) => { // iterate through all children
            if(mesh) return; //already found a result
            mesh = x instanceof Mesh ? x : null;
        });

        if(mesh != null) {
            mesh = mesh as Mesh;

            // create the mesh collider and assign the mesh
            const collider = new MeshCollider();
            collider.sharedMesh = mesh!;
            
            // create a host object to hold possible offsets
            const colldierObject = new Object3D();
            GameObject.addComponent(colldierObject, collider); // add the new collider to the new collider object

            // add the collider object under the mehs to get correct scale, position and rotation
            mesh.add(colldierObject); 

            // add rigidbody to the main object
            const rigidbody = new Rigidbody(); 
            rigidbody.isKinematic = true; // for debuging purposes otherwise it falls endlessly
            instance.addComponent(rigidbody);
        }

by user 224464722878005248

Oh, hm.

Just in case, can you comment out the colldierObject and the whole usage? Just in case if it something else happening with your scene.
Also, i made a typo in the name, sorry about that :no_mouth: colldierObject β†’ colliderObject

by user 224464722878005248

Like it ?

by user 224464722878005248

yeah

No error

by user 224464722878005248

If insert the model into the sample scene with the code it is seemingly working. Is it possible something else is interfering?

Also, not to jump into a rabbit hole, what exactly is your usecase?

What do you expect the teeth to do? Should they push each other out based on the adjustments?
image.png

Yes that’s it, if a move one of them, I need that the others follow
So for it I need colliders

by user 224464722878005248

Yes I tried too
That’s weird

by user 224464722878005248

Alright, Is it cruical that the object is downloaded from an external source?

Yes

by user 224464722878005248

I will try to add colliders before anything

by user 224464722878005248

Your model is using scaled mesh colliders which is not optimal for performance LowerTooth_42
This is hopefully ok, it make sense since it is an extra calculation, luckily your scene is small and the performance hit should not be significant.

----

Just incase, let’s double check versions.
What Needle version are you using? What Unity version are you using?
image.png

Unity 2022.2.5f1 with Needle

by user 224464722878005248

by user 224464722878005248

3.12.2

by user 224464722878005248