Connect character with the Pawn

It doesn’t work. When the character enters the trigger and clicks the E button, the character should be connected to the pawn. If the character is connected to the pawn, then I want to control the pawn. But if the character leaves the Trigger Box or clicks the E button again, the connection with the pawn should be terminated.

Pawn

Character

Actor Component

Thanks in advance!

What you are looking for is possessing a Pawn.
Basically, you tell your controller which character or pawn you want to control.
You can still use the overlap events to switch between the pawns. That should work pretty smoothly.

Take a look at these two pages to get you started.

Possess Docu

How to Possess Pawns

Hopefully, this will get you on the right track.

I want to control an indefinite number of Pawns. Character should continue to be active.

I have similar case. Multiplayer game with vehicle that can be rided by few players, one can steer.
Possessing in this case is the dead end cuz players can change seats, HUD must be still active and more things under hood. I will try similar approach like this

Just switch in input that will be redirected to ‘attached’ vehicle. If you have any progess write there.

I would still use possess for the driver. But other than that you’re right. Not the best solution.
What I would do for passengers:
When the player hits the interact button and enters the car as a passenger I would attach the player to the car. You can use sockets for positioning within the car.
For the input: I use Enhanced Input in my project. I would add a new input mapping context. Within this context only basic input is available like looking around, aiming, shooting and interact to exit the car. No movement, jumping or anything else.
In that case you don’t have to do any checks within your movement functions if he’s in a car or not.
When he exits the car just switch the mapping context back and you’re good to go.

I’m sorry. I probably don’t understand what exactly you’re trying to achieve :slight_smile:

So you want to control an indefinite number of pawns at the same time? Wouldn’t that mean that all pawns get the same input and would keep their relative positions to each other anyway?
What’s the difference to attaching the pawns/actors to the character and just control the character? Or by “control” do you mean something different than movement? Because I don’t see how the character ever leaves the trigger box if you control them at the same time.

Again, sorry about all the questions. Just trying to understand a little bit better what you’re trying to do exactly.

You should be able to very easily adapt this:

https://answers.unrealengine.com/questions/1045329/control-a-pawn-with-character.html

It doesn’t work as expected. If the character leaves the Trigger Box or clicks the E button again, the connection with the pawn should be terminated.

Character

Actor Component

Pawn

It doesn’t work as expected.

You must adapt it to your needs… It’s just a method, not a plug & play solution.

Thank you for your efforts. Unfortunately does not work. I can control the pawn, but if the character leaves the Trigger Box or clicks the E button again, the connection with the pawn should be terminated.

why is the connection with the Pawn interrupted after 5 seconds, although the character did not leave the trigger box.

Is that what you mean?

But it does not work. If the character leaves the trigger box, the connection is not interrupted.

How to end the connection with the character?

No clue but you’re doing something very strange with the array remove… you nullify the reference, make it into an array and then remove nothing from it. Those nodes do nothing - what is it supposed to do?

why is the connection with the Pawn
interrupted after 5 seconds

If the issue is time based, it’s not here - not in the screenshot. But calling End Overlap would sever the execution chain for the Add Movement Input - so something calls that.

This (red) is strange. You check before if it is player. But now anything leaving area - reset your variable… and even strange array. Check first if this is ‘player’. If this is lift anything even landscape can generate this.

I will be add some valid check. And probably before ‘==’ additional castto… but check if this help first.

It works! Thank you, you saved me.