Is there such a thing as "too many nodes(empty nodes+script)"?

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

By this, i mean using many nodes without properties, but only to be used to attach script.

For example, if we have an instance of NPC, It will have lots of node children with attach scripts and the scenario will be for a single scene, we will have 30-40 NPCs w/ each NPC having around 20 Nodes (15 Nodes for empty nodes[Node2D] attached w/ scripts & 5 Nodes for the properties of NPC[CollisionShape,Sprite,AnimationPlayer,Sound,etc…]).

That means we will have 800 Nodes alone just for the 40 NPCs for a single scene(and will increase more with other game objects).

Is there such thing as too many nodes(even though some use of empty nodes are just used to group nodes like folders) and is something to worry about?
Or are these empty nodes(Node2D w/ attached scripts) just like folders and nothing to worry about?

And if there is ‘too many nodes’, how many is the’ too many’?

To make a simple scenario:

  1. Having each NPC have their own node child of Empty Node2D+script


  1. Having 1 Universal Empty Node2D+script (parent) which all NPCs will access(Though i think it will most likely crash if two NPCs executes and accesses the node at the same cycle).

Thanks for reading & looking forward to your insight and guidance.

not sure but there is Max Renderable Elements property at Project Settings > General > Rendering > Limits > Rendering which has 65536 value.

volzhs | 2018-07-16 13:01

Thanks for sharing! I was not aware of this.

Reginhowl | 2018-07-16 19:57

:bust_in_silhouette: Reply From: Zylann

All kinds of nodes are actual objects that have their own existence in memory and in the tree (so they are not just “free folders”).

However, using the most basic Node to place a script has the least footprint and shouldn’t be much of a problem if there are many of them. I’d say it’s a good way to make “components” that appear in the scene tree, and there is no limit for those.

It might be an issue only if you plan on instancing tens of thousands of them, eventually. It depends what you do in them as well. If they are Node2D, they might be impacted by renderer limits so be wise about which node you really need to extend.

Even the most simplistic Node has a bunch of features it it, so if you are worried about this, you can also create bare scripts that extend nothing and just create them in _ready of your main character script:


func say_hello():

extends Node2D
var _component = preload("").new()

func _ready():

Thank you very much for the answer and guidance! This helps a lot!

Reginhowl | 2018-07-16 19:53