Hello, I’m another Unity refuge who is trying to build a turn based X-Com like game and I have a probably really basic question I’m stuck on.
My goal is to start with a base actor class that includes all of the basic code components any enemy or player needs (animation, movement, health, attacking, etc).
I started with animation and movement, and now that those are done I was about to add a node to handle health when I realized that because that script isn’t in the root node (where movement currently lives) nothing outside of the player scene itself would be able to access it. I would much rather each of the main components be a separate script/class because otherwise things get complicated and messy VERY quickly.
So how do I solve the problem of wanting 5+ nodes/scripts/classes to handle all of the core functions of an actor, while making those functions accessibly when the actor scene is Instantiated in a new scene?
Ideally, the root node of a scene should expose whatever functionality is necessary to control its children to the outside world.
You can read more about best practices here Best practices — Godot Engine (stable) documentation in English
For scripts that are going to contain data like health, stats,… you can use custom resources Resources — Godot Engine (stable) documentation in English
Still reading this, but this seems to be exactly what I was looking for, already started a new project so I can reorganize my scenes to account for these best practices!
Think of everything as a scene/node.
Healthbar? That’s a scene, it can manage health. Don’t need healthbar/ui to be displayed or don’t want the node to waste rendering cycles? Set it to visible = false. You can still call the methods in the script that’s behind the node. This is useful for “managers” etc.
I’m used to dependency injection, abstract classes, objects for every… well, object. But if you just think of EVERY object AND every component AND every “manager” and other logic aggregator as a scene/node - using Godot becomes so much easier b/c you stop fighting it.
Anyway, that’s what I’ve learned so far, after a few months of Godot.