- Home /
Changes to a mesh via code don't render until I interact with them through manual editor tools.
Hi I was trying to setup a system to procedurally generate 3d rooms on unity.
I used the ProBuilder API to generate a normal cube and that worked fine. But as soon as I want to do any more than that through the API it doesn't work.
For example if I want to flip the normals of the whole mesh I use this code:
for (int i = 0; i < cube.faces.Count; i++)
{
Debug.Log("Face: " + cube.faces[i]);
cube.faces[i].Reverse();
}
If I run the game now the cube stilll looks as before, but if I try to select single faces it behaves like the code worked. Also if I try to do it manually through the manual ProBuilder tool I have to use the function 2 times to make it work.
To me it seems like the code works but somehow it doesn't get rendered in game afterwards.
Has anybody had the same problem and might be able to help me out?
Cube Generation Function:
void generateBlock(Vector3 size, Vector3 position)
{
cube = ShapeGenerator.GenerateCube(PivotLocation.Center, size);
cube.GetComponent<MeshRenderer>().material = material;
cube.transform.position = position;
}
Answer by privatecontractor · Jan 28 at 10:09 PM
Hi @SigmarOD,
did you try adding:
cube.Rebuild();
Or:
cube.Refresh();
after conducting all of modifications....
@privatecontractor no unfortunately this does not work.
The Rebuild function throws a CS1061 error as it doesn't exist for ProBuilder meshes.
The Refresh function doesn't throw any errors for flipping normals but it doesn't work eitherway.
Your answer
Follow this Question
Related Questions
How can I generate a up facing quad mesh with variable resolution? 0 Answers
SetTriangles does not accept a NativeArray. Best way around this? 1 Answer
Procedurally Generated Cube Mesh 3 Answers
Strange Edge Shadows on Generated Flat Mesh 0 Answers
How can I generate a up facing quad mesh with adjustable res? 0 Answers