Debug.Drawline in editor does not operate continiously

Hello guys, we are trying to make an editor gizmo. It will raycast repeatedly and show us the path our object will take after throwing it. The tool mostly works, however it sometimes doesn’t show the reflections at all when we change the pos variable. We didn’t notice a pattern where it does and where it doesn’t. How can we make it so that it will always show the raycasts correctly. Relevant code below.

public Vector2 pos;
public bool enabled;

void OnDrawGizmosSelected()
{
if (enabled)
{
Debug.DrawRay(transform.position, pos, Color.white);
CheckRaycast(transform.position, pos);
}
}

void CheckRaycast(Vector2 initial, Vector2 aim)
{
RaycastHit2D hit = Physics2D.Raycast(initial, aim, Mathf.Infinity, lm);
if(hit.collider != null)
{
Debug.DrawLine(initial, hit.point,Color.green);
directionVector = hit.point - initial;
destination = Vector2.Reflect(directionVector.normalized, hit.normal);
CheckRaycast(hit.point, destination);
}
}

Thanks.

Since you’re using OnDrawGizmosSelected, couldn’t you also draw the line with gizmos?

Debug.DrawLine is meant for debugging play mode.