Does Godot draws only visible (on screen / camera) nodes?

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

So the question is: if a sprite node is off screen / camera, doesn’t godot draw it or is there a way to do it manually? Is turning off visibility enough? For performance reasons, lets say i have a big scene and i only whant to draw only what is on camera.
thanks in advance!

:bust_in_silhouette: Reply From: luckyNyaNya

I tested it in a project and it seems that godot still tries to draw sprites that are off screen anyways.
I made simple bots which are placed ON screen. Each bot runs to a target Vector2 which is OFF screen. When a target is reached new target is generated also OFF screen. And so on.
Then i made so many bots so i get fps drops (30-35). Then I hit a key to toggle visibility framerate is back on 60 :smiley: hit that key again and fps drops

Godot should attempt to cull sprites that are not on screen. Given the test you did, all I can assume is that the culling takes a long time, but if visibility is off then Godot doesn’t calculate that culling, hence the fps rise.
So this doesn’t prove that Godot attempts to draw things out of screen, but it does attempt to not draw them (as opposed to not caring about them at all). If you want to test if it actually draws, you should test the difference between many visible sprites on screen vs many visible sprites off screen.

I would also remove all scripts from your test since they are not part of the test and may affect FPS by themselves.

Zylann | 2018-07-18 13:01

Ah culling, that was the word i was after :smiley: Thanks for your suggestion i will try it.

luckyNyaNya | 2018-07-18 14:03

:bust_in_silhouette: Reply From: zhangyao

Hi LuckNyaNya,

I always use .hide() function to get rid of what I currently dont want, it retains its position property when hidden, but you can not interact with them in any way.
Try build a func to detect the position/area of camera, if objects out of the camera, hide them. See if it can work :slight_smile:

thanks, thats what I am doing / implementing, i was just thinking if godot do it automaticaly to save my time implementing :smiley: but with hide() collision also stops working right? I’m just curious :stuck_out_tongue:

luckyNyaNya | 2018-07-22 21:24

sorry for late reply,
yes, it will stop all interactions, like it just temporarily delete the object when use hide() and make them back when show()

zhangyao | 2018-07-30 06:32