Download

Possess Blueprint Pawn without fixed target pawn (Enter / Exit vehicle)

OK, so I have a pawn blueprint that I want to sprinkle throughout a level. I want to have the pawn play an animation when the player approaches, and then the player can hit ‘E’ to enter (posses) the pawn.
I have all my approach logic working, the thing lights up and displays the ‘E to enter’ message, and shuts down when you walk away.
Currently possessing it only works if I drag a reference to the pawn into the level blueprint and tie E into possess with that specific pawn as the target. However, this seems inefficient as I have to manually specify my possess target every time… If there are multiple vehicles in the level, or the vehicle spawns during gameplay, etc, etc, that gets unwieldy. I don’t want to have to step on a button like in the example levels… I want to walk up to a vehicle and hit ‘E’ to enter it, no matter which vehicle, where it is sitting (moved from starting point), when it spawned, etc.

So I thought I’d be tricky and write the enter/exit logic into the vehicle pawn BP so I could drive my possess logic from there… But so far I have been unsuccessful. I posted my attempts below.

QUESTION: How should you handle “possess pawn” logic without having to specify the pawn target in the level BP?

here are my attempts and failures:

  1. ATTEMPT: Box component on vehicle pawn BP. Player overlaps box, display message and set ‘enable input’ for that player, then have E possess the vehicle and disable collision on the original player pawn (save old pawn as variable for later use).
    FAILURE: You can’t enable input on an unpossessed pawn. This almost seems like a bug or missing feature… I can enable input on any other thing I have floating around, but not an unpossessed pawn? Spent hours banging my head on this one… Why allow the “enable input” option if it’s not going to DO anything?

  2. ATTEMPT: When the box component on the vehicle pawn is overlapped by the player, set that vehicle pawn in a “NearestVehicle” variable on the level blueprint. Then have E (in the level blueprint) possess the “NearestVehicle” if it’s close enough.
    FAILURE: I can not find how to reference the level variable in my vehicle blueprint. I tried manually dragging it in from the level blueprint, and it showed up but complains about the target pin needing to be connected… No idea what to connect to the target pin to to reference the main level blueprint (it’s not the value I am setting it to). I tried this both with the variable directly, and using a level blueprint “SetNearestVehicle” Function. neither worked, and one managed to crash UE4 when I tried to force it to promote “Target” to variable.

  3. ATTEMPT: ‘E pressed’ event in level BP… get overlapping actors, filter by my vehicle pawn class, ‘for loop’ through the resulting array, set the 1st result to my 'NearestVehicle," Possess “NearestVehicle” if it’s close enough.
    FAILURE: Even though I can see the overlap happening if I set up an even in the vehicle BP, in the level BP the array for overlapping actors never populates, so the for loop never does its first loop.

Plus like 3 or so more attempts that I forgot exactly what I did, but mostly revolving around trying to force the nearest pawn into the “NearestVehicle” variable.

…Any thoughts / ideas?

-Mike

EDIT: I thought I’d be sneaky and make a driver pawn blueprint, then use that as a component on my vehicle actor blueprint. Turns out you apparently can’t nest blueprints. Any other ideas?

It looks like you can actually call the “Possess” function inside a class Blueprint - you just have to turn off the context sensitive filter or search in the palette. I think your first attempt should work this way - you just need to put the input event for exiting a vehicle inside the vehicle Blueprint, and keep the input for entering a vehicle in your player pawn Blueprint.

Thanks, Thomas. Unfortunately, that doesn’t solve the problem of knowing which vehicle to enter without having to manually specify the instance in the level blueprint.
Last night I got it to work using GetActorOverlap and pulling from the resulting array (didn’t work the first time because I think I tripped a bug where the array would not reset after its first use, so I would up having to clear it each time). Today I am going to test line tracing (raycast) from the FPV looking forward, and return the hit as the target vehicle. I’ll post the BPgraph of whichever one works best back here in case someone else is looking in the future.

Did you get any further with this? Still struggling with creating network-ready vehicles that players can enter and exit at will.

I dont know about networking side of things but give this a try and see if it works for you:

Thanks, ****. That solution is a hell of a lot more complex than I’d like. I’ve managed to get sometihng to work using a button blueprint I created but it’s still rather convoluted. Will keep trying.

UPDATE: Found this… It works: https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/PossessPawns/Blueprints/index.html

Did you manage to successfully complete that tutorial? ( https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/PossessPawns/Blueprints/index.html ) I’m stuck at #15 I did follow the tutorial very closely, but I can’t drag off the, Set Near Car… i can’t find it. Anyone have a solution for this?

Ye, drag off of the As My Character C output attribute from the Cast To MyCharacter node. You should be able to access any of the member variables you defined within the MyCharacter blueprint. I set my “Near car” boolean to editable, not sure if that makes a difference.