In the previous blog ( 【UE】Display the archived value on the control blueprint ) we introduced how to display the archived value on the control blueprint. This blog will introduce how to archive the player position.
Effect
It can be seen that when re-entering the game, the character appears at the save point instead of the player's birth point
step
1. Create a new blueprint, the parent class is save game
Name it "CheckPointsSaveGame"
2. Open "CheckPointsSaveGame", create a new vector type variable named "LastLocation", which is used to store the last location of the player.
3. Create a new blueprint whose parent class is "Actor" and name it "CheckPointsBP"
Add a box collision component, we want the character to save the player's position once the character enters the area
Create a new variable named "Location"
Add the following nodes to the event graph
Run the game at this time, when the player enters the collision area, the position where the player enters the area can be printed
4. The next step is to archive this value
Create a new variable, named "SaveSubClass", and the variable type is the object reference of the saved game
Continue to add the following nodes
At this time, once the character enters the collision area, the position it enters will be saved.
In this way, we can place several save points in the scene, and once the player enters these areas, we save their positions.
5. Next, we need to reload the saved location, so that the character will appear in that location when it enters
Open ThirdPersonCharacter and add the following nodes in the event graph
The running effect is as shown at the beginning of the article.