The best way to manage a lot of characters

Godot Version

4.3

Question

I would like to make a 2d top/down game with lots of characters who each have their own texture, interaction,… Each character comes in several different colors. Each character has its own automatic activity and can have interactions with other characters…
My question is: what is the best way/structure or solution to handle this kind of situation?

THANKS

I am not sure I understand your question?

There are many ways you could handle this depending on your exact need case.

You could start by just creating scenes for each character you need, you would then instance these scenes into your game world as needed.

If they are NPC characters you could create FSM for controlling their behaviors.

I guess I have a few questions.

Are these NPC’s?
Are they all going to be going about doing their things at once?
Do you want there to be multiple instances of the same character but in different colors?

I would create scenes of character bodies with collision shape and either an animated sprite or animation player. This would be your base build for all characters, now you would save this as character_base(or something).

Now, how you do the second part depends on your game needs.

You could set it up so it has export var for its textures and colors and create child nodes for each unique behavior that you instantiate based on another export var that tells you what character it is. This is assuming you don’t want to create a million unique scenes for each character, this is also better if you are placing the characters in editor. If you are instantiating them in code then you could set it up the same, but then set each export var in editor and then save it as a unique scene with those export variables.

Your question was vague and broad so it is hard to give a more specific answer not knowing anything about your game.

const CharList : Dictionary = {"bafoon":BafoonActionNode,ect...}

@export var char_type : String
@export var texture : Dictionary
@export var color : String

func _ready():
#instantiate node in CharList using char_type as key
#set animation texture based on desired texture, using color as key

Thanks already for the response.
What I would like to do is a simulation game with animals and I have for each animal, different versions (gender, colors,…) and several animations.

Each animal has different actions/interactions.

My question is, how can I manage all of these charcteres without having to do it, one by one, manually.

As for actions/interactions, I’m busy investing in decision trees for each animal.

My question is not technical but more about the organization of the code.

I guess I am still confused by what you mean manage these characters.

If you mean you don’t want to be individually having to place them all over the map and such, then you would just instantiate them in your code. So, you would have a node that is their direct parent cycle through and instantiate them all, and set their starting positions. You could even have it set all their variables that determine what type and such that they are if you don’t want to have to call a bunch of different nodes.

How you do that depends on how random you want to be.

I can try and be more specific in how I would organize it if you can help me understand better what you mean by “manage all of these characters without having to do it, one by one, manually.”

Are you talking placing them? Choosing their types? Their genders? Their colors? How many there are?

All of these can be done with a common parent node and some code to instantiate using the variable suggestions I gave before.

I would personally organize it where you have a common parent that is the spawner/definer node. This node would control setting up all your animals and their different types, by setting variables in the animal’s code like I suggested before. It would then call the animals set_up() which would set up all of its animation/behavior tree and whatnot based on those variables. That is how I would organize my code if I wanted to spawn a lot of things without having to go into each instance individually or create a million different scene iterations of the same thing with just different colors and such.

1 Like