Inheritance advise => Actor(Combatant) vs Building in RTS game

I think I should have two different base classes for inanimate objects like buildings and animate objects like turrets or vehicles. They do share some functionality like health, armor rating and value to the opposing player when it is captured or destroyed. I know this is probably an opinionated “it depends” question, but how did you handle a similar situation?

Thank You

I think you need one class for the shared stuff and one class for the extended functionality. These classes extend MonoBehaviour and are attached to the corresponding prefabs.

But this is just one way of doing it. It depends on your general code architecture if that makes sense in your case.

1 Like

I just smacked my forehead… Thank You

Unity is a component architecture (“has a thingy”).

You are thinking about an inheritance architecture (“is a thingy”).

You may find it helpful to consider your problem without inheritance, as MonoBehaviors are already perfect components that are purpose-built to interoperate with each other while attached to a GameObject.

You CAN do it with inheritance but I absolutely do not recommend it because of the impedance mismatch with Unity’s underlying architectural choices.

2 Likes