# Loading the Next Level (UE 4.27)

**URL:** <https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [February 7, 2022, 8:46pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452 "2022-02-07T20:46:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![CurleeD85](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CurleeD85](https://forums.unrealengine.com/u/CurleeD85)\
**Post date:** [February 7, 2022, 8:46pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/1 "2022-02-07T20:46:51Z")

</div>

This time, I am trying to make another function that causes the program to move from one level to the next, once the goal in each level is achieved. I did try the OpenLevel function, only to find that objects from the first level were transported along with the player character.

I’ve thought of using multiple branches and a counter that determines which level to go to; every time a level is completed, the integer representing the level number would increase by 1. Then, the program would check the level number; if it equals 2, for example, the game loads Level 2 after the first one is done. If the integer equals 5, the game loads Level 5 after Level 4 is finished.

What would be the best way to script this?

(I did look up similar forum questions, but the included image links are apparently broken.)

---

<div class="post-metadata">

**Author:** ![CurleeD85](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CurleeD85](https://forums.unrealengine.com/u/CurleeD85)\
**Post date:** [February 7, 2022, 10:55pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/2 "2022-02-07T22:55:24Z")

</div>

Here is what I have, so far:

> **[Loading Level BP posted by anonymous | blueprintUE | PasteBin For Unreal...](https://blueprintue.com/blueprint/j3p8gkl-/)**
>
> No description provided

Please note this is from a child object of a parent actor.

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [February 7, 2022, 11:37pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/3 "2022-02-07T23:37:53Z")

</div>

Regarding what you have in blueprint right now and not your main post: usually you want to avoid many copy / paste and try and make things more automated.

 ![Screen Shot 2022-02-07 at 7.25.11 PM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/9/5/2957fa900bf74aedf5c82b68e8ea6e72881c694a.png)

For example, you can use a Struct to know what level has been completed or not:

```auto
// pseudo
struct LevelsStruct
{
    int32 LevelOrder; // Same as array?
    FName LevelToLoad;
    bool bLevelCompleted;
}

```

Have an instance of the struct per level in an array. Like this you can loop from lowest to highest looking for the first level that has not been completed. This one will naturally be the next level to load:

```auto
// pseudo
ForEach LevelsArray
{
    if !LevelsArray[i].bLevelCompleted
    {
        // Load level.
        // Break loop
    }
}

```

Looping like this will always load the next level that has the bool set to false. So if index 0 is false, meaning not completed, it checks to load next level. When level has been completed, set that bool to true and run the even again to get next bool that is false:

```auto
// Start For Loop
// loop 0
LevelsArray[0].bLevelCompleted == true // Skip
// loop 1
LevelsArray[1].bLevelCompleted == true // Skip
// loop 2
LevelsArray[2].bLevelCompleted == false // Load
// Break For Loop

```

Hope it makes sense… Wrote it like this because do not have access to UE right now. I’ll do it with BP later. The idea is to make it less iterative and easier to just add / remove / reorganize levels.

Having a struct will the info of each level will also make it a lot easier to load specific levels.

---

<div class="post-metadata">

**Author:** ![CurleeD85](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CurleeD85](https://forums.unrealengine.com/u/CurleeD85)\
**Post date:** [February 7, 2022, 11:39pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/4 "2022-02-07T23:39:35Z")

</div>

Somewhat. I’m not sure if I can implement C++ into a BP project. But okay. I appreciate the help, so far.

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [February 7, 2022, 11:40pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/5 "2022-02-07T23:40:22Z")

</div>

Its informal. The idea is the logic to implement in blueprint… also saves to write a wall of text. 😬

---

<div class="post-metadata">

**Author:** ![CurleeD85](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CurleeD85](https://forums.unrealengine.com/u/CurleeD85)\
**Post date:** [February 8, 2022, 3:46am UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/6 "2022-02-08T03:46:40Z")

</div>

I just remembered. That code is really Python, right? It’s been a long time since I’ve coded in that. Anyway, once you are able, please let me know what would work in blueprint mode. Or at least ideas on what to include.

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [February 8, 2022, 5:54am UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/7 "2022-02-08T05:54:17Z")

</div>

This is the struct (just an example):

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/3/1/e311b530ddceebe4a5e2b254b60fec103ba8e8bb.png)

In Game Instance I created an array and populated the struct for each level:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/3/5/a35cf1971bb6b0fb75b926a19f2924ead0d8ded7.png)

I’m assuming you have a blueprint in every level that calls the Event PowerOn. If that blueprint had a public integer, you could do this:

- First get a reference to the Game Instance:  

- I’m using an interface to “complete” each level. You can use that reference to update the struct corresponding to that level, in this case calling CE\_CompleteLevel passing the LevelNumber integer.  

- This is that event in Game Instance:  

- First check if the level has been completed, if not then update and continue to next level.

- Next update the bool in the struct.

- The branch checks if all levels have been completed by comparing the int with the array length-1, if not ++LevelToLoad.

- Finally call to load next level:  

Simple enough so far…

So we basically turned this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/e/9/4e99ceef5307f0791f3f568098a2fafe042d080b.png)

Into this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/2/e/92e6919ce5ff96c66c47d4034eefcffa6e9a3010.png)  
With the added bonus that if I add 100 more levels, all I have to do is update the array of structs.

[https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/5/a/35ae47befc8978527af63ee805de7938c369b113.mp4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/5/a/35ae47befc8978527af63ee805de7938c369b113.mp4)

Hope it helps.  
Also, forget the idea I typed in prev post… it’s overly complicated for the same result.

---

<div class="post-metadata">

**Author:** ![CurleeD85](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CurleeD85](https://forums.unrealengine.com/u/CurleeD85)\
**Post date:** [February 8, 2022, 5:36pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/8 "2022-02-08T17:36:53Z")

</div>

So far, I have made the structure and then declared an array structure variable under the Goal BP. But, I don’t seem to have anything to put into each array member; there are no results when I click on each pull-down bar. Was there something I forgot to do?

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [February 8, 2022, 5:39pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/9 "2022-02-08T17:39:59Z")

</div>

Share a screenshot or video to know what you are referring to specifically.

---

<div class="post-metadata">

**Author:** ![CurleeD85](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CurleeD85](https://forums.unrealengine.com/u/CurleeD85)\
**Post date:** [February 8, 2022, 5:50pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/10 "2022-02-08T17:50:00Z")

</div>

Here are two screenshots showing the structure itself and the variable when declared under the Goal actor’s BP.

 ![Screenshot17](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/6/3/063f5f4a32b6174c956be13c4fe5779ecaba7bac.png)  
 ![Screenshot16](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/c/6/7c68597d6f13cbdc99ff50f182365b731a1e7826.png)

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [February 8, 2022, 5:52pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/11 "2022-02-08T17:52:30Z")

</div>

![Screen Shot 2022-02-08 at 1.51.53 PM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/8/4/f84ac0cb538acbabe84af383757e027ee2482eda.png)  
Variable type has to be the same as the struct.

---

<div class="post-metadata">

**Author:** ![CurleeD85](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CurleeD85](https://forums.unrealengine.com/u/CurleeD85)\
**Post date:** [February 8, 2022, 5:59pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/12 "2022-02-08T17:59:41Z")

</div>

Oh! I think I got it now. Now, the menu looks something like this:

 ![Screenshot18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/d/c/3dcd29fc7fec5415b12caa86e07169da8c30bfb4.png)

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [February 8, 2022, 6:17pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/13 "2022-02-08T18:17:27Z")

</div>

Nice!

For now you can fill the info for each level.

If you like to research and complicate things to learn: You can fill the struct with a data table and / or load game.

---

<div class="post-metadata">

**Author:** ![CurleeD85](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CurleeD85](https://forums.unrealengine.com/u/CurleeD85)\
**Post date:** [February 8, 2022, 8:07pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/14 "2022-02-08T20:07:41Z")

</div>

Where did you get the BP\_GameInstanceLevel, by the way? Is that the name of the variable? I tried typing in “cast to LevelStructure” (which is the structure variable), but no such option appeared.

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [February 8, 2022, 8:09pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/15 "2022-02-08T20:09:33Z")

</div>

> [@CurleeD85](#):
>
> Where did you get the BP\_GameInstanceLevel, by the way?

It’s basically a blueprint that’s persistent through the entire game. You can visualize it as being a step above Level blueprints, allowing you to create logic that handles levels and actors distributed across different levels, among other stuff.

This video explains it very well:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/b/1/7b11150d2dfb9ab9d4e2f4dfb2cd7cedb4e480c9.jpeg "HTF do I? Use the GameInstance Object in Unreal Engine 4") ](https://www.youtube.com/watch?v=5w594D3qtLs)

Highly recommend you watch this video too… several times:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/f/5/af5394ae0955deb72218f5291e2d300d06f6c37e.jpeg "The Unreal Engine Game Framework: From int main() to BeginPlay") ](https://www.youtube.com/watch?v=IaU2Hue-ApI)

It covers a lot of info very fast, but it’s priceless. Game Instance is mentioned 7:30. I suggest watch from the beginning so it makes sense.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [February 8, 2022, 8:23pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/16 "2022-02-08T20:23:49Z")

</div>

Comprehensive example is comprehensive.

---

<div class="post-metadata">

**Author:** ![CurleeD85](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CurleeD85](https://forums.unrealengine.com/u/CurleeD85)\
**Post date:** [February 8, 2022, 9:01pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/17 "2022-02-08T21:01:22Z")

</div>

Under the LoadNextLevel event, how did you make a “Get” node with the array options from the “Level Struct Array” variable (which is “LevelStructure” in my program)? Every time I tried to click and drag from that variable, I’d only have array and integer slots when I try to get a copy or ref.

Also, this is under Goal or PuzzleGameInstance (which is my custom Game Instance)?

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [February 8, 2022, 9:04pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/18 "2022-02-08T21:04:33Z")

</div>

> [@CurleeD85](#):
>
> how did you make a “Get” node with the array options from the “Level Struct Array” variable

You mean this?

> <https://twitter.com/continuebreak/status/1133014226463858689?ref_src=twsrc%5Etfw%7Ctwcamp%5Etweetembed%7Ctwterm%5E1133014226463858689%7Ctwgr%5E%7Ctwcon%5Es1_&ref_url=https%3A%2F%2Fwww.redditmedia.com%2Fmediaembed%2Fbvjebh%3Fresponsive%3Dtrueis_nightmode%3Dfalse>

You can also drag from the output pin and search for Break.

---

<div class="post-metadata">

**Author:** ![CurleeD85](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CurleeD85](https://forums.unrealengine.com/u/CurleeD85)\
**Post date:** [February 8, 2022, 9:06pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/19 "2022-02-08T21:06:31Z")

</div>

Ah, I didn’t know I could do that! That helps tremendously.

---

<div class="post-metadata">

**Author:** ![CurleeD85](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CurleeD85](https://forums.unrealengine.com/u/CurleeD85)\
**Post date:** [February 8, 2022, 9:13pm UTC](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452/20 "2022-02-08T21:13:25Z")

</div>

Now, referring to the below image –

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/a/5/ca5fe185414e1056e97628c7f40489a973f54f61.png)

I haven’t been able to make a “Set” node for the PuzzleGameInstance blueprint in this same way as before. Also, where does it go to on the right side?

[Next page](https://forums.unrealengine.com/t/loading-the-next-level-ue-4-27/495452.md?page=2)
