4. Level Startup Scripting

When the level begins, you want the player to start at the location of the PlayerStart Actor you placed previously. In order to make this happen, you need to move the player to that location and orient them correctly.

  1. In the Level Editor toolbar click the Blueprints button and then choose Open Level Blueprint to open the script for the current level in the Blueprint Editor.

    level_blueprint.png

  2. Right-click in the Event Graph and choose Event BeginPlay under Add Event.

    begin_play.png

  3. Right-click in the Event Graph and choose Get Game Mode to get a reference to the current Game Mode instance. Drag off the Return Value pin and choose Cast to BP_OdinGameMode. Connect the exec output of the BeginPlay event to the exec input of the Cast to BP_OdinGameMode node.

    game_mode.png

  4. Drag off the As BP Odin Game Mode pin and choose End Loading Sequence. This performs some necessary cleanup after loading the level.

    end_loading.png

  5. Drag off the As BP Odin Game Mode output and choose Get Main Pawn (under the game category). This gives you a reference to the player which you can use to set their location.

    player.png

  6. Drag off the Main Pawn pin and choose Teleport (under the Utilities > Transformation category). Connect the exec output of the End Loading Sequence node to the exec input of the Teleport node.

    teleport.png

  7. In the Level Editor Viewport, select the Player Start Actor you place previously. Back in the Blueprint Editor, right-click in the Event Graph and choose Create a Reference to [ActorName].

    player_start.png

  8. Drag off the output pin on the Player Start reference and choose Get ActorLocation. Connect the Return Value output to the Dest Location input of the Teleport node.

    location.png

  9. Drag off the output pin on the Player Start reference and choose Get ActorRotation. Connect the Return Value output to the Dest Rotation input of the Teleport node.

    Copy Node Graph

    rotation.png

    Click the icon in the upper left corner of this image to copy the Blueprint Graph and paste it into your project.

Result

When you click Play in the Level Editor toolbar , you will now start off in the location of the Player Start Actor, facing the direction of the oncoming robots.

test.png