x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Simply allow first gamepad to control Player 2

So in my game you can either select one player, or local 2 player.

If you select one player, the controller and the keyboard control the first person, and since there's only one, that's fine.

However, if you select two players, the controller and the still keyboard control the first person, and if you have another gamepad then the second one will control the second player.

I'd like to have it so that just the keyboard controls player 1 and the first gamepad controls player 2. Is this possible?

Bonus, detect the number of controllers and if there are two controllers and two gamepads then each gamepad controls a player, and the keyboard controls the first player.

Product Version: UE 4.9
Tags:
more ▼

asked Nov 08 '15 at 02:20 PM in Blueprint Scripting

avatar image

ShrewGlue
434 97 83 107

avatar image ShrewGlue Nov 09 '15 at 09:30 PM

Is there a fix to this?

avatar image Syrill Jun 20 '16 at 11:25 AM

Would be very interested in this issue as well... :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

You can do it by going into Project Settings > Maps & Modes > Skip Assigning Gamepad To Player 1. Set it to true and you are good to go.

more ▼

answered Feb 28 '17 at 11:55 PM

avatar image

ImSolar
11 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hello there! After searching a lot, I finally found a solution by talking to MordenTral (awesome dude and author of two amazing plugins). Basically, the clean solution to achieve this is to create a child class of UGameViewportClient which overrides InputKey(...) and InputAxis(...). In the overrides, you can reroute where certain inputs go and both functions have bool bGamepad as a parameter so you can basically use that to determine where you want to send the input. It is necessary to set the Game Viewport Client Class in Project Settings to be the newly created class. You can make this class blueprintable and expose an Enum UPROPERTY to Blueprint so that you can actually create a child blueprint class and can change behavior dynamically at runtime using blueprints (of course the Game Viewport Client Class in Project Settings would need to point to this blueprint class).

Here is my UCustomGameViewportClient class:

 #pragma once
 
 #include "CoreMinimal.h"
 #include "Engine/GameViewportClient.h"
 #include "CustomGameViewportClient.generated.h"
 
 /** This class introduces a new Input-PlayerController binding behaviour. Through the EGameInputMethod Enum it is possible to choose the default
 * behavior (in which keyboard/mouse input and gamepad input are both binded to Player 1 [index 0]) or the Player1OnlyKeyboardAndMouse behavior 
 * (in which keyboard/mouse input is binded to Player 1 [index 0] and gamepad input is shifted to the other players).
 */
 UENUM(Blueprintable)
 enum class EGameInputMethod : uint8
 {
     GameInput_Default,
     GameInput_Player1OnlyKeyboardAndMouse,
 };
 
 UCLASS(Blueprintable)
 class SIDESCROLLER_API UCustomGameViewportClient : public UGameViewportClient
 {
     GENERATED_BODY()
     
 public:
 
     // Input Method for the viewport
     UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Input")
         EGameInputMethod GameInputMethod;
 
 
     virtual bool InputKey(FViewport* tViewport, int32 ControllerId, FKey Key, EInputEvent EventType, float AmountDepressed = 1.f, bool bGamepad = false) override
     {
         if (GameInputMethod == EGameInputMethod::GameInput_Default)
             return Super::InputKey(tViewport, ControllerId, Key, EventType, AmountDepressed, bGamepad);
 
         if (GameInputMethod == EGameInputMethod::GameInput_Player1OnlyKeyboardAndMouse && bGamepad)
         {
             // shift gamepad input to controllers with +1 index
             ++ControllerId;
             return Super::InputKey(tViewport, ControllerId, Key, EventType, AmountDepressed, bGamepad);
         }
         else 
         {
             return Super::InputKey(tViewport, ControllerId, Key, EventType, AmountDepressed, bGamepad);
         }
     }
 
     virtual bool InputAxis(FViewport* tViewport, int32 ControllerId, FKey Key, float Delta, float DeltaTime, int32 NumSamples = 1, bool bGamepad = false) override
     {
         if (GameInputMethod == EGameInputMethod::GameInput_Default)
             return Super::InputAxis(tViewport, ControllerId, Key, Delta, DeltaTime, NumSamples, bGamepad);
 
         if (GameInputMethod == EGameInputMethod::GameInput_Player1OnlyKeyboardAndMouse && bGamepad)
         {
             // shift gamepad input to controllers with +1 index
             ++ControllerId;
             return Super::InputAxis(tViewport, ControllerId, Key, Delta, DeltaTime, NumSamples, bGamepad);
         }
         else
         {
             return Super::InputAxis(tViewport, ControllerId, Key, Delta, DeltaTime, NumSamples, bGamepad);
         }
     }
     
     
 };


Create Blueprint class from this, and you'll see ou can change the Enum to whatever you like.

To change this at runtime you'll need to access this class with UWorld::GetGameViewport(), so make a function in a c++ blueprint function library (if you want to have access via Blueprints):

 class UGameViewportClient* FunctionLibrary::GetGameViewport(const UObject* WorldContextObject)
 {
     UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
     return World ? World->GetGameViewport() : nullptr;
 }

Once you have that exposed, all you need to do is cast it to your custom Game Viewport class and set the enum to the desired value.

I must say that this works perfectly for me... but I also have input on UI and in that case it isn't working, I still need to find out what happens in that case.

more ▼

answered Apr 14 '18 at 11:27 PM

avatar image

JohnnyDale
36 1 4

avatar image LaZeKler Nov 09 '18 at 12:05 PM

You can also modify the "Skip Assigning Gamepad To Player 1" setting at run time by changing "bOffsetPlayerGamepadIds" of the class "UGameMapsSettings" directly in your game instance.

Full answer in that post : https://forums.unrealengine.com/unreal-engine/feedback-for-epic/48403-keyboard-p1-gamepad-p2-please?p=1549367#post1549367

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

There is no simple fix, but a workaround. You can create your own controller class and carry out the necessary operations in its event tick. However, your problems would not end there as you would need some c++ code to disable the split screen once a level is complete, otherwise UE4 splits the screen even when you open a new level or go back to the menu. It's quite cumbersome but possible. It may be better to work for an official solution.

more ▼

answered Nov 10 '15 at 04:36 PM

avatar image

alperenakyuz
2k 62 24 111

avatar image ShrewGlue Nov 10 '15 at 08:13 PM

By custom controller class you mean a custom player controller class?

Is there any way to duplicate my current player controller class (which isn't currently accessible as a BP and work from there>?)

avatar image ShrewGlue Nov 10 '15 at 08:26 PM

Also, what would I need to edit in the custom player controller class?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question