- Home /
Pool/Cache Unity colors when used by many objects
My scenario: I'm using editor functions to draw some Gizmos in my scene view with shared colors. I have maybe 100 objects. When I select many of them at once I can see a big performance drop for a few seconds, so now I'm looking for ways to optimize my editor code.
Every object has code similar to this:
void OnDrawGizmos ()
{
Gizmos.color = new Color32(255, 255, 255, 50);
Gizmos.DrawLine(Origin.transform.position, Destination.transform.position);
}
Does it make sense and is there a way to cache/pool/batch the creation of all those colors? I don't need 100 color objects to be created every time something changes in the scene. I want it to be created only once and then be used like a constant.
So next, I thought:
public static class Constants
{
public static Color almostClear = new Color32(255, 255, 255, 50);
}
This at least let's me change colors in a single place, but does it also prevent the creation of the color every time an object needs it? What would be a way to batch this efficiently?
Thank you!
Your answer
Follow this Question
Related Questions
Vertex colours - can they improve performance? Do they affect batching? 1 Answer
UI performance on mobile. FPS drops 0 Answers
How to correctly import textures of any kind to the project? 0 Answers
does interpolation full up some kind of cache over time 1 Answer
Object Pooling, have some question marks 0 Answers