Loading a different level every time ?

Okay so this is hard to explain but i’m working on a prototype where you need to collect boxes. 1 box collected adds 1 to the counter and if you reach 50 boxes in a level i want the game to load the next level but the “collectables” variable (which is an integer) is inside the third person blueprint. How can i reference the “collectables” variable in the level blueprint so that when you reach 50 of the “collectables” it loads a different level every time.

Explaining this better that above:

I have a code in my thirdpersoncharacter blueprint that checks your “collectables” every tick and when you have “collectables” > 49 it loads “level2” but on level 2 if you collect 50 again it will try to load level 2 again and i want that to change so when your on level 2 it loads level 3 , when you’re on level 3 it loads level 4 and so on and so forth.

I apologize for my English and i appreciate every single bit of help!
Have a nice day!

First off, don’t check every frame if the player has collected 50 collectables. You should check when you collect one instead.

As for your question, you could save your levels as their number, and when you collect 50 just increment that number and load that level

I changed it to on event actor begin overlap but if i increment my number than my script would still load the 2nd level

What i mean in scripts

If i have 2 scripts

1 if collectables > 49 then open level “level 2”

2 if collectables > 56 then open level “level 3”

Still the first script would take place and “play” because i reach 49 before 56 :frowning:

  • use “switch on integer” ( integer is your curent level, default 1 ) -> - if collectables > 49 then open level “level 2”, set your level integer to 2
  • then your “switch on integer” is set with 2 → if collectables > 56 then open level “level 3”, set your level integer to 3
    – then your “switch on integer” is set with 3 …etc

You could save your level name as a variable in an array of level names. Use a “get node” with an index that you increment each time you open a new level. Use the “get” node with the specified index to change the level name variable that you feed into an “open level” node. Sample steps:

  1. In game instance (so it persists between levels) create an array of “Name” variables. Start with index 0 and put level 2’s name in there, 3 will go in index 1, 4 in index 2 and so on.
  2. Create a function in your game instance that then takes this array, uses a “Get” node and promote the index of the “get” to a variable and call it Next Level. Default it to -1. Increment the variable and then add an “open level” node after. This will make the variable == 0 the first time you call the function and thus return to you index 0, or the name of level 2.
  3. When you collect 50 collectibles from the 3rd person character cast to your game instance and call the function. Done. You open level 2.
  4. When you collect 50 collectibles in level 2, the function is called again, this time incrementing from 0 to 1. It grabs index 1, you now open level 3. Easy.