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.)
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.
For example, you can use a Struct to know what level has been completed or not:
// 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:
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:
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.
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.
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.
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?
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.
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:
Highly recommend you watch this video too… several times:
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.
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)?