I have two players but don't know how to assign input mapping to them. Help

I need somebody to give their ideas of how I can assign inputs to my characters.


I seen this code but I’m not really sure it’s good for two players. Maybe I don’t understand about the nodes that are being used here, if anyone can explain it to me that’d be great.

So the idea I have is to create two input mappings and trying to find a way to assign that for two players.

In class settings you can assign default input actions

This code will work in networked multiplayer.

Each pawn executes their own Event Begin Play and Get Controller will return their personal controller which will be different for each pawn. Then each pawn will add the same button mappings for their controller.

If you need different controls for each player controller (for split screen) you can do it like this:

1 Like

where is class settings?


Is there a way I can combine this code when the players spawn? Also is it fine to put all of this into the level blueprint or should I use a different blueprint?


this is what I got and I guess this is fine? what’s your opinion on this?

In the class BP there’s two tabs at the top for settings and default

(post deleted by author)

I see what you’re talking about but I cannot imagine how it works for my project. This will be used for a fight game so I need to be more aware of how inputs will be transfer.

What do you mean by how inputs will transfer? Like for different characters/abilities? With Gas you can have the same IA mapped to several different abilities, just assign the abilities to the characters

The code I showed you is in the Character and you should leave it there.

In your particular setup it would be useful to add an InputMapingContext variable that is InstanceEditable and Exposed on Spawn in your character.

That way you can directly set what context will be used when you spawn the character
image
.

Leave the actual setting in the character.

So the reason why I put this code in the level blueprint it’s for a situation where player one and player two want to switch. Instead of being on the left they want to be on the right. In my head I thought if I create two input mapping context I can use that to let the character know which player is controlling them when that character spawn. Also I had to keep in mind of different characters that the player want to select

I’m just wondering is it still possible even though this logic is in the character blueprint. Another thing that is in my head is to redo this code for every character I want to create, but I think that could be solved by making every other character a child blueprint of the first base character

like you have two characters but they don’t know which of the two players are controlling them. Especially, if player one wants to be on the right side and player two wants to be on the left, So let’s say the first character that will be spawned on the left needs to know player two controller or play one wants to control them. That’s what I mean about assigning.

Ok, so it’s a local multiplayer. I dug a bit deeper and I found this:

Tell me if it works for your case.

yeah. I’m working with local multiplayer right now, sorry if I didn’t mention that. As I’m trying to wrap my head around this video can you answer a few node questions?


When you get a reference from something you know where it’s getting those data from, But when people use “get player controller” or “gets player character” it’s hard for me to completely understand the function of these nodes. From my research I believe that information is already build in the engine itself? But what that information is and how can I use that is not explain to me.
Basically.

  1. Does these nodes reference a Pawn that the Unreal Engine creates for the project?
  2. If so where can I access that information so I know what I’m working with?
  3. And what example can you give me to understand this node function?
    I just want you to know. You’ve been very helpful and Responding back to me, and I appreciate that a lot. Thanks

First to answer your question in the beginning. Get player controller/pawn nodes are a part of the Game Statics and can be called from anywhere in the code. They both have an index input and will return the local player with that index. If you have a single player game you only have one player and they only have one pawn so that means that if you use it with index 0 you are set. Might not be the case in local multiplayer though depending on how you realize it.

Now for the numbered questions:

  1. Yes. Get player pawn and get player character return the local player’s pawn. (character is derived from pawn) The player controller is the abstract player representation that can possess different pawns during the game and persists even when the pawn is destroyed e.g when your character dies.
  2. When you get the pawn variable you can execute any method targeting the pawn or set any public variable.
  3. This is just a very small (and out of context) subset of what you can do with those nodes and how to get the data within:

Note the text bellow the name of the node that says “Target is XXX” this means that you have to provide the correct target. Sometimes the target is the object you are making the blueprint in so then it can be just “self”.

Of course all examples need an execution (white) line from some event. Some might need continuous execution (from Tick Event) to see the effect like AddInputVector.

Pawn is what confusing me right now so let me get this right.
I see people make codes in a Pawn and put that in the world to handle certain things. So in my head the Pawn that we are talking about have codes inside of it, and pawn is just a way to access that information. Right? it’s confusing to understand something that you can’t visually see.

You said “get the pawn variable” and explain that the more detail. When I was writing this I just realized you probably can if you search up “get player” or any “get” node. right?

(“Target is XXX” this means that you have to provide the correct target.) So its looking for the same or a child of the pawn class?

image
Can you show me how are you using the set node variable. How is connected to a different blueprint

Also I need to understand “Enhanced input local player subsystem” is that another Pawn, and how does this work?

I watched the video and yes this is exactly what I was looking for. thanks.
It help me understand that a lot of these codes are C++ and the fact that I can override it.

Also let me get this right, “Get player controller” creates a controller Pawn, and index set how many players are there, like a player ID?

You rarely put a pawn in the world manually. The world is created along with your GameMode object. The Game Mode then spawns the default player controller and its default pawn. You are probably talking about Actors.

I’m not sure where exactly are you referring to but “GetPlayerPawn” is global and can be used in any blueprint and it will give you the pawn variable (blue line with type Pawn) you can connect to the target of nodes that require Pawn target.

Yes exactly. If you don’t provide a proper target the blueprint will not compile.


This graph in the Pawn will show the mouse cursor when you hold “G” and hide it when you release it.

The “Enhanced input local player subsystem” is a global system that handles input. You can read more here: Enhanced Input in Unreal Engine | Unreal Engine 5.4 Documentation | Epic Developer Community

No. The controller must be already created. GetPlayerController just gives you a reference to it. When you create a local player controller with CreateLocalPlayer you can give it a index. Then you can use that index in the GetPlayerController to get a reference to any of the created local controllers. Pawns are different type of objects.

I know that the pawn that we are talking about is a default pawn that is created with the engine, but I was trying to compare those two with their functionality.
Pawn is just a way to access that code inside of it. Is that right?
I want to look up how to use a Pawn and now I’m even more confused, it doesn’t seem useful unless you want to create a character from scratch.

Sorry I should be more specific but this was also very useful. I was trying to see how you was using Boolean variables. I wanted to see the mouse cursor code, and how did you use this to activate and deactivate the mouse cursor. I see that you’re using true and false but I don’t know in what way.

Lets say if I want two players I need to create two “local player controller” and give them index one and two, then I need to check which index is which to set up the inputs for them. Is that right?

The Pawn is just the type (class) of object. All pawns have common functionality. If you want to know exactly what - right click in your blueprint, remove the “ContentSensitive” tick and look for Pawn:
image

Epic are quite diligent to put the correct category for all their method and functions.

If you want to know what derives from what you can go to to Tools->ClassViewer:
image

The code for actually showing the mouse is somewhere in the C++ file of the player controller. I don’t know how it works exactly and it’s not important. The beauty of it is that you can use the objects provided without knowing every detail of their implementation.

If you want 2 local players you create only one more local controller. The first is already created when you hit play and it has an index of 0.

Now the problem with this approach is that controllers are assigned exclusive right on a hardware input. Controller 0 has mouse + kb and Controller 1 gets gamepad 1. As far as I know there is no way to make two controllers share the same hardware input.

If you want both players to use the same hardware device (e.g. the keyboard) you’ll have to do with only a single controller, possessing one of the characters and puppeteering the other as explained in the video tutorial I’ve posted.