Should I use resources, classes, nodes or autoloads?

Godot Version

Godot 4.6

Question

I’m trying to wrap my head around what are these things.

From my own understanding, .tres can be saved and loaded from the disk, so it’s a great data containers.

But classes can also do that (?) and nodes also have the ability to hold data and functions and autoloads can also do that but global.

I’m honestly confused and I’m paralyzed on which one to use.

Did you already read through these?

Classes don’t hold any data. Classes are just blueprints that explain how to build an instance / object.

Nodes are just instances of different classes, they don’t “hold” data by themselves. The instance of said Node does. Not the node itself. The only way this would be true is if you marked something inside your custom node as static, but for the most part I do not recommend doing that for anything that is too complex.

Thank you everyone. I appreciate the tips :clap: !

You’re confusing categories.

Autoloads are nodes.

Both - nodes and resources - are classes of various kind.

I believe the classic internet wide response to this is ‘yes’.

Except autoloads, avoid them if you can.

Ok simple explanation:

imagine a fruit tree

Classes

Class (i talk about class_name cuz class is local version of them) is like the name for a tree, e.g tree is a tree, not a rock, bush, car, house, Tree = Tree

Nodes

Nodes are unique instances of the script, so they’re like single trees on their own, e.g you have node for tree that grows under your window, you have node for a tree under your neightboar’s window, you have node for tree that grows next to the road, but they each share the same name - tree, tho they’re unique on their own

Resources

Resourcse hold static data, so imagine them as maybe DNA, every tree have it’s DNA that’s shared, each tree knows how it should grow cuz it have DNA, but you can’t change DNA without creating new variant of it, what’s the difference between resources and variables - variables should be used like your trees small memory they have that can change, while resources are blueprints / static variables that it uses

Autoloads

Autoloads hold data across the entire game, so they’re like sun or weather, every tree can know what weather is it, or if it’s night or day ect. cuz they all can realize this from autoload

In short:

Classes - they’re broad used blueprints that every tree belongs to

Nodes - they’re single objects of tree with their own variables

Resources - they’re static data that trees can use - but can’t change it

Autoloads - they’re scripts every other script can access and loads outside the main scene

hope this clears some things out :]

That is very bad advice without context. Don’t avoid Autoloads. Understand when to use them and the effects they have on your game. I see this advice all the time, and it led me down a very bad road for 6 months where I was creating my own Singletons instead of just using an Autoload.

For what?

The answer to your question is, “Yes, you should use them.”

You should definitely research them, but the answer to which one is all of them - when it is appropriate.

That’s like saying .csv is great for saving data. Sure, it is. So is .tscn. So what? What’s your actual question? What data are you trying to save?

You haven’t asked an actual question. You have vented about your paralysis. This is an example of the XY Problem. You are trying to build something, and you started researching how Godot works. Then you asked how Godot works, and what to use. But the actual question you should be asking is, “How do I do X?”

What brought you to this question? What are you trying to do? It would also help to know your background. Do you have programming experience?

Yes, my mistakes for not providing enough context. I was not in a good mental state because of the confusion and boredom from the complexity of starting a new game engine.

I have some experience but they are mainly created with game libraries like KAPLAY.

These game libraries provides a very flexible way to structure your games, so I got used with this workflow of creating my own data containers and global variables just by simply declaring them like a normal variable.

Diving in Godot was a very strange and new experience to me. And the reason I asked those questions is because I want to understand those concepts so I can use them in a way Godot designed it to be.

My main problem is how to structure my game. Like where do I store the game state data (current level, money, etc)? Should I put it at the root node? I’ve been watching tutorials on YouTube about these things and I still cannot understand them. But the replies above are very helpful!

So I made a very simple game, it’s like Candy Crush, and right now this is my structure

  • Game (Root node) (Node2D)
    • Level (Node2D)
      • Grid (Where candies are being destroyed) (Node2D that instantiates candy.tscn)
      • Inputs (That allows candies to be destroyed) (Control)
    • Start Menu (Control)
    • Main Menu (Control)
      • LevelSelection (Control)
      • LevelEditor (Control)
      • etc

So as you can see, everything is under the Game node. That decision came to be because of how I think communication be between Inputs and Grid.

Right now, Level listens for signals that Inputs emit and gives it to Grid. When a level was finished, Grid emits the ‘level complete’ signal, and Level listens to that and emits ‘reward the player’ that Game node listen to.

And naturally, I decided to put all of the data and enums inside the Game node since the nodes are under the Game nodes anyway and gave it class_name so it’d appear in my scripts.

I really don’t know if I’m doing this right but it works, I’m just afraid it would make my codebase hard to update, messy and scary.

I would appreciate your thoughts on what I’m doing wrong and what I can improve.

Thank you so much for this, this is what I was trying to find for eternity.

For anyone who’s as confused:

Nodes vs Resources
Nodes give you functionality: they draw sprites, 3D models, simulate physics, arrange user interfaces, etc. Resources are data containers. They don’t do anything on their own: instead, nodes use the data contained in resources. Anything Godot saves or loads from disk is a resource. Be it a scene (a .tscn or a .scn file), an image, a script

I suggest you to read the links @wchc provided. They answered all of my questions.

I highly suggest this video also on how to read documentation properly: https://www.youtube.com/watch?v=MJmIW2Dwdss

Classes explanation