I have a list of gizmos in a simple gizmo drawing manager. This list is updated from different parts of the codebase, usually from Update() methods. It goes something like this:
public class RenderGizmos : Singleton<RenderGizmos>
{
private List<GizmoData> gizmos = new List<GizmoData>();
public void AddNewGizmo(GizmoData[] gizmos)
{
this.gizmos.AddRange(gizmos);
}
public void AddNewGizmo(GizmoData gizmo)
{
this.gizmos.Add(gizmo);
}
void OnDrawGizmos()
{
if (gizmos == null) return;
for (var i = 0; i < gizmos.Count; i++)
{
//draw gizmos
}
}
}
Can you advise me on when to clear the gizmo list? Ideally I would like to clear it every frame. However:
- Clearing it at the end of the OnDrawGizmos() method will render no gizmos (as I suspect this method might be called several times a frame).
- Clearing it in an LateUpdate()/Update() method is dependent on execution order, sometimes it draws gizmos, sometimes it doesn't
- Clearing it in a Coroutine has rendered no gizmos (but it might just be dependent on the execution order as well)
I would like not to be dependent on the execution order so I prefer not to use the Script Execution Order system.