Creating a World Map Using a Spline | Unreal Engine 5.6 Tutorial

 

Introduction 


For this tutorial I'm going to break it into two parts. The first part is Part 1: Prerequisites and Part 2: Creating the Movement. To complete Part 2, you must complete Part 1, so it is recommended to read through it.


Part 1: Prerequisites

Goal

What we need to do in this section is create a new control scheme and player so that it is different from our actual game.

1.Input Actions

  1. Start of by creating a new input action, so right click and search "Input Action".


  2. Once created open it up and make sure the "Value Type" is set to "Digital (bool) if not change it.

  3. Name this Input Action "IA_Forward"

  4. Repeat steps 1 and 2 and name this Input Action "IA_Backward".

2.Creating Necessary Blueprints

  1. Let's create our new player. To do this right click and add a new "Blueprint" from there select "Character". Name this whatever you want. I'm going to call it "WorldMapChar_bp".



  2. You would want to add your mesh to this character, but for this tutorial I'm just going to use a cube.

  3. Now we need to create the path our player will follow, so slimily to step one create a new "Blueprint Class"; however, we need this to be an "Actor". Name this "WorldMapPath_bp"

  4. Open up "WorldMapPath_bp" and hit "Add" in the top right. Search for "Spline" and add it into the viewport. Once done don't touch anything else.


  5. From there let's create our stopping volume, so let's create another actor and let's call it "StopVolume_bp".

  6. Open up the stop volume and hit "Add" in the top left. Search for "Box Collision" and add it. I'm going to call it "box"



  7. Click on "box" and make sure "Generate Overlap Events" is ticked "True" if not do so.

3.Mapping Context

  1. To create the context right click and search for "Input Mapping Context". Name this "WorldMapControls".

  2. Open it up and under "Mappings" add our newly created input actions ("Forward" and "Backward").


  3. Click the plus button to the right of the action and select your desired key bind for the action. I'm going to use the left stick on a controller, but this is up to you.

  4. Repeat step 3 for the other action.
  5. Finaly, we have to create the player controller for the game. I'm going to duplicate the player controller used in the Unreal template, but you can also manually create one.


  6. Finaly, we need to change the mapping context used. To do that open up "BP_WorldMapController" and look for the "Add Mapping Context" node and swap the current one for "WorldMappingContext".



4.New Game mode

  1. For this step I'm going to be duplicating the already existing game mode in the project but if you wanted to create it manual just search up "Blueprint Class", and click "Gameplay Mode Base" in "Add". I'm going to call mine "BP_WorldMap_GameMode".

  2. Once created open it up and under "Class Defaults" swap "Default Pawn" and "Player Controller Class" to our newly created character and controller.



5.Wrap Up 

  1. Create a new level and override the default game mode with our new one. Don't forget to name and save the level.




Part 2: Creating the Movement

Goal

Now that we have our player and a spline, we need to now create the movement.

1.Movement

  1. Open you player class and in the "Event Begin Play" node drag out and get a "Get Actor of Class". Once done select "WorldMapPath_bp" as the actor.

  2. Promote this to a variable and call it "Path".


  3. Add a "Custom Event" and name this "Forward".


  4. Drag out from "Forward" and add create a new Timeline. I'm calling this "Movement"


  5. Before doing anything else create two new events "Pause" and "Backward". Plug "Pause" into "Stop" and "Backward" into "Reverse"


  6.  Open up the newly created timeline and hit "Add" in the top left. Click "Float Track" Let's call it "MovementTrack"

  7. Right click and hit "Add Key to Curve Float" twice. Set the "Length" and "Value" to 0 for one and for the other one set the "Length" to 5 and "Value" to 1 for the other.


    Note the value is a key factor in how fast the player will move. 

  8. Once completed close out of the timeline and from the "MovementTrack" node drag out to get a "Lerp". You probably have to disconnect the default value and plug it into "Alpha".


  9. Next get the "Path" and drag out to get "Get Spline". From that drag out from "Spline" and get a "Get Spline Length" node.


  10. Connect "Get Spline Length" into the "B" value for the lerp.

  11. Drag out again from "Spline" and get a "Get Distance Along Spline" node.


  12. From that "Get Distance Along Spline" node switch the "Coordinate Space" from "Local" to "World". Then connect the lerp "Return Value" into the "Distance" pin.


  13. Drag out from the "Spline" once again but get a "Get Rotation at Distance Along Spline". Just repeat the previous step from before to this one.


  14. Finaly drag out from the "Update" pin from our "Movement" timeline and get a "Set Actor Location and Rotation". Plug the location node into the "New Location" pin and the rotation into "New Rotation".



  15. Then to wrap things up just get the enhanced input action for forward and plug it into our custom "Forward" event and simply repeat this process for the "Backward" event.

2.Creating Stop Volumes

  1. Open up the "StopVolume_bp" and from "Event Begin Play" drag in a "Cast to WorldMapChar_bp". From the "Object" pin get a "Get Player Pawn".

  2. Right click on the output of the cast and hit "Promote to Variable". I'm calling this "PlayerRef".


  3. Click on "Box" in the top left corner and search for "Event Begin Overlap".

  4. Drag out from "Other Comp" and get a "==" sign.

  5. We are going to see if the players capsule is colliding so get the "PlayerRef" and get "Get Capsule". To cap this off plug that into the "=="



  6. Get a branch with the "==" as the condition".

  7. Get the "PlayerRef" variable again and use that to get our "Pause" function and connect the "True" into it.


3.Wrap Up

If you've reached this point congratulations because you're now finished. The purpose of this section is just going to be how to set up the Spline in the level.
  1. Start off by dragging "WorldMapPath_bp" into the world.

  2. Next either drag or create a player start and place it over the start of the spline.

  3. To make the spline bigger click on it and then click the last dot on it, Hold "Alt" on your keyboard and drag out with the "Move" tool. Then freely move the points however you want.


  4. Finaly to add the stopping points drag out the "StopVolume_bp" and place them in parts of the path you want the player to stop, and just like that you're done.

Comments