currently working on a game in godot and i feel like i have a ton of spaghetti code. a lot of things have smart designs, but a lot of other things are shoved into hard references to node instances, singletons, etc. etc. how do you usually decouple things in godot? i know this is a broad question, but i'm looking for broad answers-- situations where this has been relevant to you, times that you have struggled with this, stuff like that. i'm curious!
I don't have a firm answer, but seeing as how I'm gonna be starting work on a world editing tool in Godot after I get some shuteye (somewhere in the ballpark of 400-500 beats from now) I wouldn't mind thinking this one over while my ADHD's in overdrive, and I could probably use whatever I come up with later for my own stuff! Sadly, I know *very* little about singletons and instances... I haven't done a lot with the engine besides character controllers and little environments to run around in, so I'm not exactly a pro. That said...
What are some examples of stuff that's hard coded that you want to decouple?
You know, I was just thinking about this specifically for myself.
I'm going to try to plan out my architecture in advance, for once.
My thinking is to hold all functions in singletons, practically the whole game. And the only thing scripts on objects can do is call the singletons.
That way, moving nodes around will basically never be an issue, and I know where to find everything.
Some obvious scripts for me would be GameStateManager MenuManager IngameUIManager IngameEventManager AudioManager, and so on...
As I said, I haven't implemented this at all, but it's something I want to try.
Oh and another bonus is modularity. Scripts like AudioManager should be useful in pretty much any game.
Not sure what your situation is but use @export to be able to use different values for multiple nodes using the same script.
You can also make custom Resources which are basically classes (you can just make normal classes in scripts but resources and more user friendly).
You can also autoload scripts and orphan nodes that you can access anywhere through the Globals tab. I use this for accessing settings values storing level data and global functions such as a function to shake the camera or a function that instantiates and plays an audio clip.
also if you're using the same node in multiple places, make it into a scene.
Additionally, learn how to make a state machine, that will dramatically help with modularization.