Load level on button press

Hello there, just a simple question that I’m sure has a simple answer…

How do I program in (in a 3rd person game in case that matters) so that when the player is both inside a trigger box AND presses a certain key it will load them into a new level?

I have it figured out for loading when entering the trigger box, but it’s getting it so that it’s both that I can’t figure out.

Thank you!

@Ballto

In either your character / player controller blueprint, or the blueprint for the level switching component (the one that contains the trigger box) you can retain a boolean variable that’s set based on whether or not the player is inside the volume.

Then, in your [Event Interact] or [Event Key ‘E’] pressed event handler, branch on the “isInTriggerVolume” boolean and fire off your console command or level load in the “True” execution branch.

If this doesn’t make sense let me know, I can whip a video together.

Thanks,

Thomas

If you could make a video that would be fantastic. Thank you!

So, just for the record [MENTION=12316]Thomas Ingham[/MENTION] I finally got this to work. You were of course right in what you said to do, it just took me some time to understand what it was you were exactly telling me to do.

So my next question is, right now I have it set to just simply “Open level” which will take me to the levels player start point. So now, how do I instead have it so that it takes me to a certain specified spot?

My Basic goal here is Walk to building, E to load the buildings level, then when I want to level the building go to the door, press E to go back to the first level, but in front of the door.

There are multiple ways you can do this. The way I’d ping-pong that information back and forth would be through the game instance. You’d need to create a custom one and set your game mode to use it; in your project settings. Inside of the GI, set up a variable in it like “Player’s last transform(you’d only need location/rotation and can leave scale at 1) before map transitioning” and probably a boolean like “Has the player recently gone into a house so I know to use custom location or not” or something.

So along these lines:

  1. Walk into trigger volume and use door
  2. Get game instance and cast to your custom GI as it, update transform variable in game instance and flag the boolean true
  3. Load next map
  4. When you leave that map and go back to the previous map, it will need the main map’s level blueprint to do a check FIRST(begin play), before placing the player.
  5. The level BP would cast to the game instance and check to see if the boolean is flagged true. If it is, then place the player at the location/angle and unflag the boolean. If it’s not flagged, then spawn the player at a default location (like if you were transitioning between a forest to a town map or something).

I wrapped up what I was doing and decided to make a quick video explaining this in a bit more detail. One thing to note, for your application of “stand in zone and press use” setup would be to just bind the key’s pressed and released to a boolean that sets it to true on pressed and not true as soon as it’s unpressed. It’s not super fancy and techincally you’d want to make it more detailed that that where it would check for trigger volumes first, but you get the gist. You’d need to do this on the player character or player controller, but from within the level BP, you could get player character>cast to [player character’s bp name like thirdpersonplayer or whatever]>get the [usekey] boolean value. On the beginoverlap part, you’d swap out the gate stuff and just make a branch with and the =player AND usekeydown. That would allow you to cut out the timer and the open/close events.