Debug.DrawRay in Update

Hey Guys,

Can’t find a way to fix it. I am drawing a ray/line between nodes. And it works great until I am trying to edit node locations. Every time I update node position a new ray is drawn , but old one stay on the screen.

Looks like Debug.DrawRay doesn’t allow to clear it from the screen.

Is there any thing better to use?

Here is with no duration parameter
7429598--909770--Draw_01.gif

And this is with set duration7429598--909773--Draw_02.gif

Sounds like you should be using Gizmos from within OnDrawGizmos rather than Debug.

Also note that neither of these will ever be visible in a built game, so I hope you’re only making debug tools. If you need a line in-game, use LineRenderer.

2 Likes

Hi @StarManta ,
Ok tried gizmos before, but they a bit limited, can be called only from Unity OnDrawDizmos function.
For the lines above I have separate functions… not sure how to transfer all of these into on OnDrawGizmos!?

// Debug road edge vector
    public void DebugSegmentVector()
    {
        Debug.DrawRay(StartPosition, GetDirection(), Color.red);
    }

    // Debug offset vector
    public void DebugOffsetVector(float distance)
    {
        Debug.DrawRay(StartPosition, GetOffsetVector() * distance, Color.blue);
        Debug.DrawRay(StartPosition, GetOffsetVector() * -distance, Color.blue);

        Debug.DrawRay(EndPosition, GetOffsetVector() * distance, Color.blue);
        Debug.DrawRay(EndPosition, GetOffsetVector() * -distance, Color.blue);
    }

Apologies, stupid question. I solved it.

Ok so OnDrawGizmos works well.
One question though.
Over the course of the game I create lists with positions. First I have one and all gizmos are displayed as soon as I add second element into the list only second element gizmos are displayed. First disappear.

I am using foreach loop inside OnDrawGismos to go through elements of the list with all Vector3 positions.