To bind actions and axes in the character blueprint class, I may have multiple such character instances for each new APlayerController. Merely 1 Action Name (e.g. avoiding
UseSkill_P2, etc) is required for each character by adding the node in the Player Controller. However, for more functionality the same is required in cpp.
What I've tried:
When I bind actions and axes (delegates) in the
InputComponent->BindAction("Attack", IE_Pressed, this, &AMyController::DoSomething);, then spawn multiple players with
UGameInstance::CreateLocalPlayer(index, err, true), the editor will crash on pressing Play in Editor (Alt+P).
The error thrown during runtime is:
Access violation - code c0000005 (first/second chance not available) and referencing the line where the first
ActionBind appeared, e.g:
A common solution can be found in this wiki post it seems. In short, overwrite
GameViewportClient and set it as default, then within, overwrite
InputKey and increment the player controller index for each input device (gamepad) used.
As mentioned previously, this would require the project to specify a unique Action Name for each player index e.g.
There is also some confusion that needs to be cleared up.
AControllerwill not be created for each input device connected.
- 1-viewport-multiplayer isn't supported as split-screen. (Weird naming, but good for search engines).
- Spawning new Local Players is generally done in your override of
AGameMode::BeginPlay. I made it up to the deriving BPs of my Game Mode to call
CreatePlayersto create up to the set amount of players.
Skip Assigning Gamepad to Player 1will allow keyboard to be used for player 1.
Hopefully there are some common best practices to tackle this problem. Any suggestion is very much appreciated!
PS Here is the related unreal answers hub question.