Creating Multiple Units

Godot Version

4.5

Question

I’m making a turn base strategy game; however, I don’t know whether it would be better to make multiple scenes for each unit that stores data (health, attack damage, movement, etcetera). Or would it be better to have all the units stored in one scene. One detail is that I plan to make a HUD that is displayed when you interact with a unit on a individual scene and I would like to know if that is practical too.

It’s better to make a base scene with a custom class. Make it something modular and can be used for all the units. Then, all you need to do is change the vars like name, sprite, behavior, etc. when adding a new instance. The HUD can be part of that base scene as well, changing content based on the scene instance’s name for example. This reduces the need to constantly duplicate resources and makes it really scalable.

What do you exactly mean by custom class?

You can create custom classes in godot by adding this line after the extends line:

class_name YourClassName

It’s basically like creating a custom node. After you do that, when you add a node, your custom class will appear on the node selection screen. Here, I created a Player and Enemy class that extends from the CharacterBody2D node:

You can try to do this and add some export var parameters to it so that each instance can be different depending on what you need it to be.

1 Like

You could probably do this with resources too.

Like Mrdicerack said you can make a base scene for your units with a script that pulls all unit variables from resources. You basically make a resource for each unit and then assign it to the unit when it’s created.

I did something similar for a weapon system a while back but I’m too rusty to give you code for it.

Hope this helps!

1 Like

What I understand from this is to create a separate scene to keep all the different types of units and then call on them when I need to in the main scene?

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.