Download

Character class inheritance, am I on the right lines?

I am currently planning a game which features multiple playable characters. I understand that I should extend the existing character class with variables that will be common among my characters(health, armor etc) to then extend for each individual character, but would I need to create ones for things like speed which are already in the basic class? On top of this, each character will have it’s own individual abilities but basic function would be the same (walk/run, aim, shoot, switch weapon) so would i put the script for these actions in the class that each character would inherit?

I know that for weapons I will want to create a class extended from actor with variables for things like weapon spread, damage, range, fire rate etc. but how would be the best way to put them onto my characters? Would it be reasonable to assume I create a variable in the character class for the primary and secondary weapons and can link the weapons to the class?

Any further tips or advice about this kind of thing would be greatly appreciated
Thanks all

Many questions in here, I guess you are basically asking for a best practice on the game design’s character module.
My opinion:

  1. Write down in paper the features first, like what type of game you are aiming for, first person shooter, third person view, etc…
  2. Write down in paper a prototype of how you imagine the characters will be selectable, because you mention there will be several characters in the game that you will be able to play (Will you press Tab and change char? Will you open a menu first?)
  3. Once you have your prototype, write down in paper what I call “Cases of Use”, I’ll give you an example:

Case of use A: “Be able to switch control over 2 different characters already placed in the game, when you switch, camera will focus the new character”
Case of use B: “Characters will have different Attack animations and different Weapons Models”

I just mentioned 2 Cases of Use that I can think of how would be achievable:
A: Create a camera Blueprint that can focus a new character when told to do so
B: 1) Create an Interface that holds the GENERIC methods to be shared among different types of characters
Ex. StartAtkingActor, ReceiveHIT, GetHealth, GetMana, etc…
Interfaces define the WHAT but not the HOW (Body/Implementation)
2) Create different Character Blueprints that inherit from Character that implement the previously created interface
Each character will handle its own Animations and implementation of each interface’s methods.

That’s a way to start, more structured thinking that can lead to better questions!
Good luck!

1 Like

Thank you for the detailed reply! The actual aim is to eventually make a multiplayer co op game in which you chose characters before the level, so I guess the blueprint interface thing is the way I should go about it? I’m doing the whole learn as I go along so apologies for the mess of questions in my initial post! I’ll take a look into blueprint interfaces because I have only really read a little about them. Pretty confident on the sort of thing I need to look into now, many thanks!

It’s hard to answer with a simple Yes or No, you would need to put your questions and game sketch in paper.

But if you want to know where you could define Speed, you don’t need to define that on Each character nor using an interface with methods.
What I would do is:

  1. Create a new Actor Component called BPC_GenericUnitInfo
  2. Add Variables, Speed, Health, etc
  3. Create several characters that inherit Character, add a Component of type BPC_GenericUnitInfo to the Character, and set the default values on each character blueprint

This way you don’t need to redefine the parameter and you can get them no matter what type of Blueprint owns that component

By the way first make the game work as a prototype, once you feel very confident on UE4 in all these aspects you can google Unreal Engine 4 Replication, you will need that for your multiplayer features

Rockseller is right and there are many ways to skin a cat.

You can use an interface for the basic variables you will use for each character.

You can also make a base character like you mentioned and expose variables to blueprint defaults such as Max Health, Speed etc… Then when you create a Child Blueprints you can change the mesh etc… Define in the character blueprints what animgraph to use and then in Blueprint defaults you can just edit the defaults to 150 Max health 600 speed without adding more blueprints to that class. Then you can just add the abilities on a character per character basis.

The weapon system you mentioned I would do similar to the above create a base shooter weapon that has the variables like, bullets per shot, spread, damage etc… and then you can again create a child blueprint change the mesh and default variables.

Then in your character blueprint when you cast to the weapon to edit varibles like IsFiring etc… You would cast to the weapon that the class uses and that cast would change per character.

You should look at Generic Shooter on the market place. I am not sure the price of it anymore it was very cheap when I picked it up and it taught me a hella lot. Good luck

Thank you for the information. I took a look but generic shooter is now $60, bit out of my student price range! I have been learning how to use interfaces and they seem very useful, so for my character i’m going to use blueprint interfaces for taking damage and things like that. Thankyou for your guidance on the weapon system aswell, I think I have a good idea how to go about this all now!

Another option for characters is to make a hollow base class and have a blueprint structure for each character. The player controller would select and pass the struct to the base pawn on Construct (Cast to PlayerController-> Get Struct -> Set all the variables in the pawn)

The Struct would define the mesh, anim blueprint, health, speed, loadout, abilites etc. A Blueprint Enum would have the ~4 characters(random number), you would use an “Switch on (your enum)” to specify which pin/struct to execute and pass to the pawn class.

A UMG element would control the Enum Selection. You could make Actor Components for each character ability and have them slot in with the struct.

The above thought process is also how you can do weapon loadouts, but in those cases the player is defining the struct themselves and passing it to their pawn

Whatever what you decide to do it, you will most likely need to have the Player Controller pass which Actor Class(Character) to spawn.

Anything you need to able to do dead/alive or un-possessed should be done on the player controller. Anything that is unique to the actor(s) being controlled should be on the actor class

Just ran across this super helpful thread as I had the scenario or case B situation and wasn’t sure how to create the action i.e. animation attack within the children. I thought about interfaces but I was implementing them inside the children calling their own function within their own blueprint which was silly …lol . It makes more sense to implement the BPI in the parent… thanks alot! this made my day :wink: