I’m trying to do something fairly simple: I want to move some vertices of a ProBuilderMesh in an editor script. This seems to be simple, but I’m finding that after doing so, the mesh either doesn’t visually update in the editor, or it updates and looks completely broken until I manually interact with its vertices.
First, here’s the code I’m using:
public static void SnapProBuilderNearSnappedToGrid()
{
var currentObject = Selection.activeGameObject;
if (currentObject == null)
{
Debug.LogWarning("No Object is selected.");
return;
}
var proBuilderMesh = currentObject.GetComponent<ProBuilderMesh>();
if (proBuilderMesh == null)
{
Debug.LogWarning("Current object has no ProBuilderMesh component.");
return;
}
var vertices = proBuilderMesh.GetVertices();
foreach (var vert in vertices)
{
vert.position += Vector3.one * 0.05f;
}
proBuilderMesh.SetVertices(vertices);
//ProBuilderEditor.Refresh(vertexCountChanged: false);
//proBuilderMesh.Refresh();
}
In this script, just to test things out, I’m simply moving the verts a small distance. Here’s a random shape I’ll run this script on:
After running it, nothing looks like it changed in the editor. But if I deselect and reselect the object, I’ll see its vertices have moved, but the editor is still showing the faces in the wrong position:
If I select one of those vertices, and move it, all the faces instantly return to where they belong. But I don’t want to have to manually interact with the object every time I run a script on it.
Okay. So I uncomment the line of code above ProBuilderEditor.Refresh(vertexCountChanged: false);, as I saw that as a suggestion in another thread, but that doesn’t change the result.
So, instead, I uncomment the line proBuilderMesh.Refresh(); That still doesn’t cause the object to display properly, and now it emits three errors to console:
Mesh.uv is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array.
Mesh.normals is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array.
Mesh.tangents is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array.
I’ve checked, and the object has the correct number of all these things, so I don’t understand why it’s giving errors. I’m not changing the number of vertices.
So, in short, no matter what I do, after I call SetVertices, the object doesn’t refresh properly in the scene view until I edit it with one of the Probuilder scene tools. How can I correctly set the vertices in code, and have it all look correct in the editor after? Thanks.




