Unity locks up when drawing WireCubes
So I am currently using a script to create a grid out of the world, and this works fine so long as I don't try to visualize anything. Is there a problem with the performance of Gizmos.DrawWireCube and Gizmos.DrawCube when run in the OnDrawGizmos() function? I know that these are the culprits for my lockups because when using simple Debug.Log outputs I have no issues but when I try to draw a cube for each of my grid nodes Unity has a seizure. here is the code where I draw the grid, which would be really handy for visualizing which nodes are currently activating a check I have elsewhere.
// Gizmo drawing for debugging
public void OnDrawGizmos()
{
// If gizmos are being displayed
if (displayGizmos)
{
// Initialize the grid
InitializeGrid();
// Draw overall area covered by the grid
Gizmos.DrawWireCube(transform.position + (Vector3.up * (worldSize.y / 2.0f)),
new Vector3(worldSize.x,
worldSize.y,
worldSize.z));
// If nodes are being displayed
if (showGridNodes)
{
// Create the grid
CreateGrid();
// For each node
foreach (GridNode node in grid)
{
// If node is walkable
if (node.Walkable)
{
// Set gizmo color to cyan
Gizmos.color = Color.cyan;
} else
{
// Set gizmo color to red
Gizmos.color = Color.red;
}
// Draw a cube at the node's position
Gizmos.DrawWireCube(node.WorldPosition, Vector3.one * nodeDiameter);
}
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612163735im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to fix editor freezing after code change? (during build) 0 Answers
Best way to draw squares of changing colors? 0 Answers
Shaders & Shadows: How far can I use for my mobile game for good performance? 0 Answers
Can atlasing also decrease performance? 1 Answer
Question on Physics.Simulate Behavior 0 Answers