controler BP and different characters : best practice ?

Hello every body !

In my solo game, the player will play as several different characters and each character has his own gameplay (a wolf, a human and a bird).
for now, I have implemented the wolf and the human but I think about adding the bird now and after the last reunion we get with team of the project, it is more and more possible that we add a gorilla and an elephant.
I use the Quality Game Settings I bought on the market (here’s the manual).
This asset allow the player to bind the key he want for the game and that’s why each input is deals by BP and all of them pass through the controller BP.
In my controller BP, I have a lot these things : controler-3.jpg

I will soon change this to set a variable (int or string) for each playable character and replace the branch with a switch…

Then, the events are managed by the character BP and every thing’s fine ^^

My concern is that for each input, I will make this switch thing to redirect the event to the character actually played. I’m afraid that this cost me a bit in performance…
Should I make several controler BP (one by character) and change it in runtime, when the played character is changed ?
Or maybe the cost I fear is very small and should not be bothering me (it applied only on input, after all…) ?

In the case I keep all in one controller BP, I will remove the “is Valid ?” Node… I know what character is played :slight_smile:

Edit : It seams I can’t easily swap controller at runtime… So I will put every thing in the same controller BP :slight_smile:
Is there a better way to deals with the numerous switches I will have then ?

Yup there is one.

  • “BP_PlayerController” -> listen to inputs
  • “BP_PlayerCharacter” -> has a function for each input, function that does nothing
  • In your “BP_PlayerController”, create a “CurrentCharacter” variable of “BP_PlayerCharacter” ref type, it is a pointer to your current Character
  • “BP_WolfCharacter” and “BP_Gorilla” are both child blueprint of “BP_PlayerCharacter”
  • each of your “BP_ChildCharacters” override the input function to do what they need to do
  • when switching characters, you update the value of “CurrentCharacter” in your “BP_PlayerController”

Ok, thanks a lot Yun-Kun :slight_smile:

When you say “a function for each input, function that does nothing”, you mean have an event that triggers nothing in character_BP and does something in gorilla_BP, or I have to create a “real” function that is trigger by the event and redefine this function in the child BP ?
Don’t mind to answer this, I will do the test ^^.

Thank again !

Make an Interface which mirrors the Inputs and let your Character/Pawn implement it.The Controller simply calls the Interface functions on the Controlled Pawn.
You don’t have to distinguish between Pawns this way

So, Mr Interface, we meet again…
I definitely need to learn what are these interface thing, it’s the third time I heard of them.
I have a lot of work, then :slight_smile:

Thanks for the lead, Raildex_

Yeah that’s also another way to go.

But to me it’s not the best case scenario here.

I bet all of your characters are sharing common properties like health, energy or whatever. It would be easy to code them in the character parent class and then modify / override the functions you want in character child classes.

In fact, your solution please me a lot because I understand it and it seams natural to me :slight_smile:
But, I see an opportunity to learn something with the raildex way ^^

I think I will implement the two :
Yours for the final result and the one from Raildex to learn about interface.
I feel this is important :slight_smile: