More than one player in multiplayer controlling a pawn

It’s a simple pawn; only slides on one axis.

Before I even start; is this even possible?

I got it working for one player; using onClicked/Released in the level BP. I’m going to give it a shot in multiplayer now.

It’s definitly possible one way or another. Did you tried possessing same pawn with secound Player Controller?

Not yet; I’m using getController, where the target is pawn. There is not a parameter for index?

I’m going to see what else can be done.

It seems like I might just have to repossess the pawn every time a player clicks on it.

Alright; I haven’t been able to get it to work.

I tried finding documentation on the possess function, the first thing I found was this:

It says there’s a one-to-one relationship between the controller and pawn.

What’s your way, because if it works that is fantastic. Otherwise it would seem each player will have to wait to use the pawn.

I’m going to keep on trying to find more documentation on how it actually works.

edit:
I just looked at the cpp and it’s definitely 1-1. I’m trying to avoid rewriting Possess; but it would seem I have to.

So I managed to put together something that works for this. Instead of attempting to possess the same pawn with multiple controllers I used an input event in the controller to trigger pawn movement. You can call a custom event within the pawn (I called it Clicked) that passes the Player Controller that clicked on it. You can then check within the Pawn if the Controller is the Pawn’s or not and alter the behavior accordingly. In order to get it to work in multiplayer I had to use a variety of Server/Client events. Basically, I had to have two events within the player controller. The first was the input event (left mouse button in this case), that called the Server event, which passed the controller to the pawn. The Pawn event ran on the server, but used two Multicast events, one for if it was clicked by the owning controller (Clicked By Owner), and one if it was not (Clicked By Other). It’s a little complex, but it saves rewriting Possess!

I don’t have access to the engine right now to put together the blueprint, but I can try to make my process more clear. If it’s still unclear I can post the blueprint at a later date.

I started with the object I wanted to be clicked, which would be the player’s pawn. That pawn got a PlayerController blueprint (which, by definition, is unique for each player).

In the controller:
I used an input event for the left mouse click to check for a pawn being clicked. You can use the GetObjectUnderCursor, or something like that to determine what was clicked (I don’t have the blueprint in front of me right now). From that I called the server event in the controller. For the server event, I just had it call the server side event in the pawn that was clicked, passing itself as the controller value.

In the pawn:
I made a custom server event called Clicked, which took as input the Controller that clicked on it. I then checked whether the Controller that caused the clicking was the same as the pawn’s own controller. If the controller that clicked on it was the pawn’s controller, I called the multicast ClickedBySelf event. If it wasn’t, I called the multicast ClickedByOther. You can put your specific actions in those events, depending on what you want to do. The multicast makes sure to run everything on both server side and client side.

I hope that clears things up a bit, but let me know if it doesn’t!

1 Like