5. Level Completed Scripting

When all the robots in the wave have been recalled and the level is complete, you want the player to return to the Hub and continue the normal flow of the game.

  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. In the Level Editor Viewport, select the Odin AI Wave Manager Actor you place previously. Back in the Blueprint Editor, right-click in the Event Graph and choose Add On Wave Completed.

    wave_complete.png

  3. Drag off the exec output and choose Delay. Set the Duration to 5.0. This will allow a brief period after the level is complete before the player is taken back to the Hub.

    delay.png

  4. 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 Delay event to the exec input of the Cast to BP_OdinGameMode node.

    game_mode.png

  5. Drag off the As BP Odin Game Mode pin and choose Bind Event to onBeginLoadingSequenceDone. Drag off the event input and choose Add Custom Event. Name the event ReturnToHub.

    loading_event.png

  6. Drag off the exec output and choose Begin Loading Sequence to start the loading screen. Connectthe Target input to the As BP Odin Game Mode output from the cast node.

    begin_loading.png

  7. Drag off the As BP Odin Game Mode output on the cast node and choose Get Main Pawn to get a reference to the player. Drag off Main Pawn and choose Get Controller to get a reference to the player's Controller. Drag off Return Value and choose Cast to Player Controller to make sure it is the Controller of a human-controlled player, which is necessary to execute a console command.

    controller.png

  8. Drag off the exec output of the ReturnToHub event and choose execute Console Command. Enter open hub_evn in the Command property. This will send a command to open the Hub level. Connect the Specific Player input to the As Player Controller output on the cast node.

    Copy Node Graph

    console_command.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 the wave is complete, the loading sequence begins and the player is taken to the Hub.

fade.png