Can a high number of nodes cause huge performance issues?

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

I’m building a small indie 4x styled space game similar to stellaris (but in 2d). I’ve done galaxy generation. My current galaxy generates a ton of “stars” in a radius of 7000 x 7000. Each star is a Node2D, with a sprite and an area 2D with some code that tells the game how that star should behave.

A high-end game will have around 2000 stars… that are all basically pixel sprites. Should my game take a massive performance hit? And if so… is this unavoidable (e.g. 2000 star games should require you to have a better PC) or is there a better way to approach this? At the moment I don’t notice much (FPS counter reads 165 fps flat with some slight dips but I’m not sure if that’s just a weird coincidence)

I generate all the stars and their system on galaxy load, then plan just to store everything in a save so subsequent launches don’t need to re-generate everything. They just place everything instead. While the galaxy is already loaded, no code is actually being executed besides some camera movement code.

With all that said, is it okay to just leave my galaxy generation and node structure as-is, or is there a possible better approach I should look into?

:bust_in_silhouette: Reply From: SnapCracklins

In my experience with Civ and such, 4x games overall can be pretty taxing on lower-end PCs for sure, especially when the data begins to change for all your points through a game. Of course, sprite resolution can play into this and obviously, the smaller the size of resources, the less data churn.

What you’re working on is probably honestly out of the scope of my expertise, but it seems like you could just hide the objects that are off-screen so they don’t soak up data and free the queue when they are not visible. You could be sure to run a function that stores that data you need anytime, listens for visibility with a signal to itself, yield as it works, before it disappears, then re-instance it when it reappears?

Your game sounds awesome btw. Hope you succeed!

I’ve thought about that but I think adding and removing nodes from the tree constantly might also get taxing. Was hoping maybe there’d be a more direct/simpler approach.

And thanks! It’s been a really fun project to work on!

scarletred012 | 2022-03-22 20:24

You can use “visible = false” and “set_process(false)”. When dealing with higher number of entities it’s better to process them by groups/chunks instead of one by one.

kelaia | 2022-03-23 13:51

Would you use the viewport for this? So like … check viewport boundaries and load in nodes based on where the viewport edges are?

scarletred012 | 2022-03-23 17:22

This tutorial should prove helpful as well

GD Quest tutorial on Visibility Notifiers to save processing power

SnapCracklins | 2022-03-23 18:18