What is the best way to load Node?

Godot Version

4.2.1

Question

Hi,

I’m currently designing a card game where I’ll be using many cards like card_a, card_b, and card_c in both my card collection scenes and battle scenes .

I’d like to achieve better performance, but I’m not sure if Load and Instantiate are CPU-intensive. Here are some thoughts I have:
A. Create a pool that loads all the cards when the game starts and then copy these card nodes when I need to use them in scenes?
B. Load the nodes using Load(“res://MyScene.tscn”) and Instantiate() them when I need to use them in scenes?

If there’s a better approach, please let me know.

Thanks

If we are only talking about a handful of objects, then either should be fine. Unless you are loading thousands of objects it shouldnt be a problem.

Personally for me I would go with option A though for something like this.

Mainly because it would be good practice in object pooling in general.

Take the following with a grain of salt. I have not done this in Godot yet.

Preferred method

Because this is a performance question, I believe making an object pool (A) is the preferred method. Objects being spawned are loaded in memory from the get-go so loading is minimized.

I assume you can simply load and instantiate X amount of instances into an array and then add/remove the instances to the scene tree when needed.

Note

If you’re still in the design phase of your project, you shouldn’t be worrying too much about performance. Generally speaking, you should start optimizing when performance becomes a problem. Performant systems may take longer to implement which reduces iteration speed.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.