Here’s a tutorial I wrote on using components to help keep your code organized.
Nice! I like it!
Thank you! I just started on a new project and it felt nice to remind myself what worked well in the previous one.
Removed by mod
That would definitely be an improvement, using classes is probably more robust. In my case, the project wasn’t too huge and it was solo, so I never hit issues with string references.
It’s a good practice to adhere to proper design patterns even on smaller projects. I also work solo on small projects :). It doesn’t really cost you anything to work with classes, it’d even say it’s easier once you get a hang of it
@mrsgreenpotato @TheLongPrice Isn’t the string reference just in the GetNodeOrNull call? I prefer to just export the nodes I need, so I don’t build up Node-structure dependencies in the code. Therefore I don’t have “Magic strings” in my code (almost) at all.
Removed by mod
@mrsgreenpotato what case do you have in mind where an export is not flexible enough? Also, do you return a Variant or generic Node(2D/3D) of a function like that or are you working with Generics then? So you do: GetNode<Bumpable>() for example?
Removed by mod
@mrsgreenpotato ahh ok, could you extend from a base node type and add this function respectively?
We’ve defined “entities” in our project and each Entity-Type has a script for some basic functionality (to define that it IS an entity etc.).
In our project a CharacterBody3D entity is an “Actor”, while a RigidBody3D is an “Item” for example. And we’re basically only working with these and define components for them that we can retrieve via a Dictionary<StringName, Resource>
@mrsgreenpotato (2/2) and in our case, we’ve put every piece of data into resources where we export the values we need. If we need a node in a scene, we just export it and it’s mostly a direct childNode of the scene. All in all we have a system where the example zombie consists of the following components: Ai, Model, Stats, Info, Sfx, Chemistry. These have their own scenes that get added to the entityNode. In the end there’s no need for such a helper function basically :D (at least yet)
Yes, as long as you know what components are inside the Zombie scene, then you can export it. But the idea of being more flexible is that you shouldn’t need to update the Zombie class when you add a new component to it. E.g. You want the zombie to be “Bumpable” now (for some reason :)), then you should be able to just add the Bumpable node to your Zombie scene and that’s it. With your approach, you’d need to also reference and export it in the Zombie class first.
Thanks duder