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:
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?
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.
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?
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?