How To Control Two Different Characters With Keyboard?

I’m struggling with this issue like forever, although I should have not, but I’ve done a lot of researches about this issue and no approach would work for me.

Please, Help me to get my development cycle forward, because this issue is really slowing it down.

what is the most working approach to control 2 different characters using Keyboard Inputs, but sharing one Camera…

I’m only able to control only one Character, why there’s no way controlling both?
Note that I’m working with a fresh new ThirdPersonProject Template without any modifications to anything.

FINALLY I’VE MANAGED TO DO IT! After a lot of researches and headaches, it turns out that the answer is a little bit tricky and requires overriding your key mappings over some base engine classes (i don’t currently remember), but what I knew that The engine is limiting using keyboard for multiple Players, and instead it forces using Keyboard for controlling whoever Character possessed by Player 0, and the rest of the possessed characters are controlled by Gamepads.

I really don’t remember the steps, but I know you should search about an article of overriding keyboard controllers in Unreal Engine, and you should find an article talks about how to do this step by step.

after that you should proceed normally with your workflow: me myself I’ve created 2 players in a level blueprint, using Create Players Node, and I’ve set its index number to a MAX Array beginning from 0 to 1.
then I’ve created 2 separate characters that each of them has different key mappings inside of his blueprint, then in their Auto Possess section: I’ve set Auto Possess to Player_0 (for the first character), and for the second character I’ve set Auto Possess to Player_1. I’ve also deactivated their camera components, and I’ve Set View Target for A Unique Camera Actor which tracks both of them.

for more information contact me.

Thanks for your answer! But I couldn’t find the article of overriding keyboard controllers, could you please tell me which section you found it in Unreal Engine?

instead of that I will give you the game viewport client (subclass) headers which is pre-edited to remove the restriction of keyboard. … follow these steps:

  1. Download the attachment and extract the files.
  2. Move both files to <Your Project Folder Path> \ Source \ <Your Project’s Name Folder>.
  3. Open your project.
  4. Compile these two files if needed (using visual studio)
  5. Open your project settings in the engine and select General Settings.
  6. Under the Default Classes header you shall find Game Viewport Client Class
  7. change it to MultiplayerViewPortClient (which the customized subclass) instead of GameViewPortClient.
  8. now in order to spawn the players you will have to create players in your level blueprint. (in my case I’ve created 3 players: one for the master camera actor which tracks both of them, and the others for my spawned character)

  1. Auto Possess your characters with players (according to how many players you want to possess or to have an individual controller) in my case I've possessed MainCharacter with Player_1 , and TheSecondCharacter with Player_2 , and the MasterCameraActor with Player_0
  2. map your special keyboard inputs to each one of them.
  3. Enjoy. :slight_smile:

follow[link text][2]

So kind of you! But I cannot find the source folder in my project folder,I don’t know why…

Should I create it by myself?

glad to help :)… but, what’s the name of your project? where its location? do you have visual studio 2015 (or 2013)?

I would suggest to open your project and create the sub-class by your self (in this case create a subclass of GameViewPortClient) and name the subclass mutliplayerviewportclient (IMPORTANT), visual studio well auto compile and build the files for you… after that, you should locate and open the two generated files (the header, and the source code by Visual Studio), and on the other hand open the 2 files I gave you in the attachment, then Copy their code lines and paste them in your 2 generated files accordingly, at last… Compile and wait for Hotreload proccess to complete and continue with the tips I gave you. :slight_smile:

contact me in case you encountered a problem. :slight_smile:

it’s strange not having a source folder in your project’s folder… this is my project folder which titled CleanSheet:

Following your tips, I have succeed changing it to mutliplayerviewportclient, and after I created the subclass, the Source folder appears, really thank you!
When I create another 2 players and set view target to a specific camera, the whole scene is black! Have you ever met this problem? Besides, I use “is player controlled” node to test if the character is controlled, it prints false, that means it does’t work…I’m so confused about this…

108903-test+whether+controlled.png

][1]

I solved the view problem by setting “Edit - > Project Settings-> Maps&Modes → Use Splitscreen” to false and set only player 0’s view target to the specific camera, that does make what I want! And for the "is Player Controlled‘ Node problem, though it still prints false, I found that the other two characters can respond to their keyboard input event, that’s great for me!
Thank you again for your kind help!

You’re doing fine, brother. :smiley: (y) glad to see it work for you! =)

the only way you could check whether your actors are possessed correctly is by doing this for every character’s blueprint:

GetController (Pawn) [node] > GetObjectName [node] > PrintString [node to Tick or beginplay].

  • if screen is giving you a valid name, then the pawn you’re checking for is possessed correctly by the player controller shown on the screen.
  • if not, you may expect to see an invalid name shown on the screen titled: “none”. :smiley:

Yes, it prints the valid name! So happy!

Is it possible for different skeleton base character ?

sure :smiley: … as long as the character can be possessed by a controller then it should work without problems.
take into consideration that this workaround may get out-dated in new engine releases.