I’ve added an integer to take into account the next level index. However when I finish “Level_000” and want to go to “Level_001” the level starts from the beginning when I click “Next Level”. Does anyone know a way to fix this issue?
I went back to play with my game and found out that when I play from the “MainMenu” level it starts as “Level_000” but is in fact a different map, and when I click next level it proceeds to go to “Level_000” which is the level I do want to be the first level. The next level button does seem to work to some extent but just not on the levels, or in the order I would like it to.
I tried to create a level select menu through an on click button. One button would open Level_001 and another would be directed to open Level_002. When I tried this out in game both buttons when clicked would open Level_000.
Tell me about your level list please and where you get the opportunity to click the button you’re showing.
Also tell me where do you set the “LevelIndex” variable of your Player Character.
Also, you’re removing your Widget from its parent before calling an open level, just get rid of the “Remove from Parent” - this destroys the widget and might prevent it from executing any other actions.
Also, why are you “Adding to Viewport” here, this means you’re trying to display the widget in which the button is. But if you’re user is clicking the button, it means it’s already being displayed. You can get rid of it too I suppose.
Is the “LevelIndex” variable persistant through the levels? Means: is it a Variable of GameInstance or is it saved/load with savegame?
Cause as far as i remember, variables of Blueprints get reset during level loading, when not set inside of a persistant Class like GameInstance.
So, your Level index will always be 0 at start of a new level… Doesn´t matter of you put a add Node behind
If i look at your first shot (OP), you add 1 to LevelIndex - But forgot to SET the new value into LevelIndex.
LevelIndex = LevelIndex + 1
That way your LevelIndex is read, increased by 1, and than Set to be the new value.
It’s not a variable of GameInstance, I placed the variable within my EndTile blueprint. Within my EndTile blueprint I created a Level Setup which contains the Level Index. I can change the level index here before starting a game and it will load the appropriate level. It’s the transition between levels that does not seem to be working.
I suspect your “Cast to character” in your “EndTileBP” to fail because it is not loaded yet whereas your end of the level is. You should add a print to it and see what it says.
Definitely see what integer it is outputting with a print string! Also not exactly sure why you’re creating a new widget and then removing it from parent on click…I don’t think that code is needed is it?