Need to disable and enable Collider after mesh.Refresh() ?

I’m trying the MeshEditorScene under “Assets/Samples/ProBuilder/4.4.0/Runtime Examples/Runtime Editing”.

  • I extrude the top face of the cube to make it higher.

  • When I hover mouse over the top face, it is no longer highlighted. And I cannot extrude this top face again.
    6476690--727358--upload_2020-10-31_17-39-42.png

  • It looks like this is caused by collider not being updated after the mesh has changed.

  • So I added code in MeshEditor.cs (Line 20 to 23) to “refresh” the collider. After this change, when I hover the mouse over the top face, it is highlighted and can be extruded again.

        void UpdateDrag()
        {
            var distance = GetDragDistance() - m_DragState.offset;

            var mesh = m_Selection.mesh;
            var indices = m_DragState.meshState.indices;
            var vertices = m_DragState.meshState.vertices;
            var origins = m_DragState.meshState.origins;
            // Constraint is in world coordinates, but we need model space when applying changes to mesh values.
            var direction = mesh.transform.InverseTransformDirection(m_DragState.constraint.direction);

            for (int i = 0, c = indices.Count; i < c; i++)
                vertices[indices[i]] = origins[i] + direction * distance;

            mesh.positions = vertices;
            mesh.ToMesh();
            mesh.Refresh();

            //======= "Refresh" collider =======
            var col = mesh.GetComponent<Collider>();
            col.enabled = false;
            col.enabled = true;
        }

Question:
Is this how it’s supposed to behave? Do I really need to disable and enable the collider to make it work?

Environment:

  • Unity 2019.4.13f1
  • ProBuilder 4.4.0

Anyone knows the answer :slight_smile: ? Is this a bug or I’m missing something?

If you look in the Utility class for that example you can see that it’s using the physics collider for object picking. If you don’t want to use a collider then you’ll need to implement another method for picking the object. The good news here is that face, edge, and vertex picking don’t rely on physics, so once you have an object you are good to go :slight_smile:

Thanks for the tips! I tried SelectionPicker.PickFacesInRect() and it could give me the object that was under cursor without using collider.

1 Like