Here’s a tutorial I wrote on using components to help keep your code organized.

  • mrsgreenpotato@discuss.tchncs.de
    link
    fedilink
    arrow-up
    1
    ·
    2 months ago

    Correct, I’d also use exported values if possible. But that isn’t flexible enough in some cases, because you’d need to individually export all possible attributes that the node might have.

    For it to be more flexible, you could have something like this:

    for child in get_children():
      if child is ClassNameHere:
        return child
    

    That would give you the same result as described in the article, without string reference. You could make a static func for it and call it a day :)

        • Paragrimm :godot:@mastodon.gamedev.place
          link
          fedilink
          arrow-up
          0
          ·
          2 months ago

          @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>

          • Paragrimm :godot:@mastodon.gamedev.place
            link
            fedilink
            arrow-up
            0
            ·
            2 months ago

            @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)