Welcome back everyone. In the last video we set out to create a Game Instance blueprint for the purposes of setting up our game timer. In this one, our goal is to set up our levels time limit, depending on which level was selected. Now note, we only have one level to select right now, but we'll show you how you could set this up for multiple levels. I'm going to start out working in our Widget Blueprints here. So I'm going to jump into my UI folder.
And I'm going to access my w BP Start Menu, double click on that guy to open them up. And I'm going to jump on over to the Graph tab. Now Currently, we have this script where once we click on the button that says level one, we're going to open up one, simple enough Well, I'm going to do something a little bit more fancy here. I'm going to create some separation between these two nodes because I'm going to put in a little bit of script between here First thing I'm going to do is I'm going to right click, and I am going to type in get Game Instance, you have seen me do this before for getting a game mode, but I'm going to do a get Game Instance because I want to cast to my BP Game Instance, in Why am I doing this? Well, the reason I'm doing this is because I want to set some variable in my BP Game Instance.
Remember when we cast is something we can talk to any variables, functions, etc, that live within that blueprint. Now, if you remember back from last video inside our BP Game Instance, we created this variable called level selected and it's got a default value of level one but it could be set to two or three. Jumping back to my w BP Start Menu. I now want to talk to that. So I'm going to drag a wire off of this In type in set level selected, I want to talk to that variable. Make sure you hook in your execution wire like this.
And because we selected level one, I want to make sure that in my game instance, I'm saying we have selected level one, you can click this drop down and change that. And then I'm just going to keep the flow of execution here by hooking this into my open level one. And let me just left click marquee selection, tap that sikhi and type in level one selected, like so. Make sure we have compiled and save this. Now I want to jump on over into my game mode game play blueprint. So coming back to your framework folder, jumping into game mode gameplay in our Want to add three new variables, come under the variable section, click this plus variable and I'm going to make one called level underscore 01 underscore time limit.
I will change this to be an integer. And with that, I can simply select it, right click and duplicate it. And I'm going to call this level o two time limit. Then right click on that duplicate level three time limits. And I'm going to compile here so I can set some default values. So I'm going to change my level or one time limit, my first level time limit to be 120.
I'm going to change my level oh two time limit to be 150 seconds. I'm just coming up with some numbers at random here. Level three short let's make it be 180 seconds. Okay. With that we've got this Event Begin Play note where we are currently showing the HUD and starting the game music. Let's add some more functionality, shall we?
So let's do this let's right click type in get Game Instance and you guessed it, we're going to drag a wire off of this and we are going to cast to our BP Game Instance we want to talk to that in some way. Let's make sure we hook in this flow of execution like so. Okay, next I'm going to drag away out of our SBP Game Instance and simply type in get level selected Oops. And then what I'm going to do is drag a wire out of our level selected here. And I am going to bring in a node called a select node. It's this guy right here.
Now what's really cool about this node is depending on which option is selected, right here, in our game instance, whatever it is set here is our level selected. We can change the return value. What do I mean by that? Firstly, I'm just gonna plug in my level oh one time limit to here. That's 120 seconds level oh two time limit to here. Remember that one's 150 seconds and my level three time limit into here.
Remember, that is 180 seconds. And then I'm going to bring in my time limit here, my game time limit. I'm going to click that. And I want to set that. And I'm going to plug this in like so. So let's understand what we are doing here.
We want to say here in our game mode gameplay that upon beginning play, we want to cast to our BP Game Instance. And we want our games time limit to be either 120 seconds, 150 seconds, or 180 seconds. Well, how do we determine that? Well, we're going to determine which one of these it is, whenever we select a level here in our BP Start Menu. So currently in my BP Start Menu, I am saying that when we click on the level or one button We're going to cast to our game instance. And we're going to set our level select variable to be level one.
So Upon selecting level one here that is going to inform our game mode blueprint that level one has been selected. So that is the time limit that we should set our game time limit to be. Let me just bring a marquee selection around this bit of script right here, left click and drag, tap that sikhi set game time limits based on level selected Okay, I'm gonna Compile and Save really quickly. And now I'm just gonna jump in and play and the time displayed should be accurate to what we have it set So right now it should be because we click on this level one button, it should be set to level one, which in our game mode gameplay is going to then select this hundred and 20 seconds as our time limit. So let me just jump in and play. Select level one, you can see our time limit is currently 120.
Now, we don't have a decrement at all yet that is still to come, but you can see that that is working. Okay, but we also had it set to 120 before so is it really working? Well, let's test it out even further. Let me jump back to W BP Start Menu. And let's say that when I click on level o one button, I am actually going to set our level selected to level two. Okay, so what that's going to do, let me just Compile and Save this is over in my game mode blueprint.
Upon beginning play here. We're going to be casting to Our Game Instance blueprint. And it's going to say, hey, which level was selected? What is this variable currently set to? Well, it's currently set to be level two because that is what we selected here in our BP Start Menu level oh two, we set this variable this level selected variable to be the level two option. So now here it should respect it should select the value set in this variable which is 150 seconds.
And that should be set as our time limit. So let me just jump in and play now and see if that is true. And now you can see in the upper right 150 is set. So you can see how this system can be extended now. I'm going to jump back into my BP Start Menu and change this back to be level oh one. But in the future, if you were to create a level level two, and level three, you can do a lot of copying and pasting of this bit of script right here, but swapping out the level selected set right here to be whatever level you've linked that button to.
Alright, let's Compile and Save that one more time. Again, the time doesn't decrement just yet we'll get to that but that is gonna do it all for this one guys. This is kind of a handy trick to make it so your time limit is specific to whichever level you selected. We'll see you guys in the next video.