Line gets deleted after drawing it

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MemokingMH

I use draw function to draw a line (I wanna make smt like those boards where you can look value of money n stuff ). I get two points, draw a line between them, and repeat this process. But everytime I draw a new line old one gets deleted. How can I prevent that from happening

:bust_in_silhouette: Reply From: skysphr

If you’re using draw_line() inside a _draw() call, the buffer gets cleared as soon as you update again. To keep things drawn, you need to either:

  • keep track of all your draw calls and redraw everything when needed, or
  • use a Viewport with “render target clear mode” set to “never”, and a ViewportContainer to actually draw the viewport on the screen.

Do I have to use a script in viewport to make it work

MemokingMH | 2022-02-19 04:43

The object that is drawing things inside the viewport (aka a child of the viewport node) needs to be the one doing the _draw() calls.

skysphr | 2022-02-19 15:27