‫Hey, welcome back.
‫In this video, we're going to create a countdown timer so that the player knows how much time they
‫have to wait before they can start moving their tank around and blowing stuff up.
‫So we're going to show the time left in the countdown timer until the game starts.
‫So let's hop into the editor and start doing this.
‫Now I'm here in our Widget Blueprint, BP Start Game Widget, and this is the widget editor as we've
‫seen.
‫But you may have noticed at the top right, there are two tabs here, one that says designer.
‫That's what we're in right now and one that says graph.
‫And if you click on graph, it looks more like a blueprint event graph with event nodes and a my blueprint
‫tab here with various sections.
‫And this is where we can do blueprint logic.
‫Now we have three nodes here.
‫We have event pre construct.
‫This is similar to a constructor in C++ and then we have event construct which is similar to begin play.
‫So this is where it's more appropriate to do things at the beginning of the game because all relevant
‫classes are constructed by this point and then we have event tick.
‫And just like the tick function in C++, we have access to Delta time here.
‫Now we're not going to use the first two nodes, so I'm going to highlight those and delete them and
‫we're going to use event tech.
‫Now, our goal for this video is to show how much time is left and we have a three second countdown
‫timer now in C++.
‫We created a timer handle and we used the world timer manager to start a timer.
‫Everything we do here in blueprints is independent of that.
‫We're creating a completely different system of logic here, and it's just going to coincide with that
‫timer that we set in C++.
‫So this is all different and independent from the C++ side.
‫Now here in WB start game widget, we can add variables just like we can add variables in C++ right
‫here.
‫Under my blueprint, I can click add and select variable and now I have a variable called new var underscore
‫zero.
‫And down here in the details panel, which is confusingly on the left side, now we have the variable
‫name and variable type.
‫Now it's highlighted by default because it's just expected that you're going to rename your variables
‫as soon as you create them.
‫So we don't need this default name.
‫We're going to call this our own name.
‫I'm going to call it Countdown.
‫And Countdown is going to be a float variable Y because this is going to keep track of how much time
‫we have left.
‫I'm going to start it off at 3 seconds and each frame I'm going to subtract the amount of time that's
‫passed since the previous frame.
‫So we get a countdown going from three downwards.
‫Now I'm going to click Compile.
‫Now, as soon as I click compile, I can give this a default value by scrolling down in the details.
‫Panel, it's set to zero by default.
‫I'm going to set it to three by default since we have a three second countdown.
‫Time now as it stands, this is just a float called Countdown with a value of three.
‫We haven't actually changed it, but every single frame of the game, I'd like to subtract away Delta
‫time, which is the amount of time that's passed since the previous frame.
‫And that way, Countdown will constantly be updating decrement by Delta time so that we have a running
‫time count.
‫Now, here's how we can do that.
‫I'm going to take a countdown from our My Blueprint tab, click and drag it here into the event graph
‫and release.
‫Now, as soon as I release, I have two options.
‫Get Countdown and set countdown.
‫If I click Get Countdown, now I have the countdown note and if I click and drag out of its output,
‫this gives me access to the value of Countdown.
‫Now I can also click on Countdown, drag in and click Set Countdown and we have a set node.
‫We've seen these both before.
‫In earlier videos, the input pin for the setter allows us to plug in a float value and then countdown
‫will be set to that value.
‫So how do we actually subtract Delta time away from Countdown and then set that to the countdown value?
‫Well, we can take our countdown node here and I can click and drag off of it and type the minus symbol
‫on my keyboard and choose the Subtract node.
‫If I select that, then I now have a float minus float or a subtract node.
‫You'll see that it says Target is Kismet Math Library.
‫That tells you that Kismet Math Library underpins this node.
‫All nodes have C++ code at their core.
‫So what this node does is it takes two inputs.
‫It takes a float input.
‫And it takes a second float input.
‫Now, it's not going to change any of the variables we're passing in.
‫It's simply going to perform a calculation and return that value that is the result of the subtraction.
‫Now I'd like to take count down and subtract Delta time from it so I can take the output pin called
‫in Delta time from the event tick node and plug that straight in to the second input in my subtraction
‫node.
‫So what I'm doing is I'm taking count down minus delta time and then this gets the result.
‫Now initially count down is 3 seconds and delta time is a very small value.
‫It's the amount of time in seconds that's passed since the last frame.
‫So this would be a tiny amount.
‫So what will result the first time this is executed is three minus a tiny amount.
‫And what I'd like to do is set the value of countdown equal to that result, every single frame.
‫So each frame countdown is being subtracted from little by little.
‫And that way it will keep the countdown from 3 seconds going downward.
‫So I'm going to take the return result from this subtraction node and plug it into the input for the
‫set countdown node.
‫Now, this isn't going to do anything if I don't connect the execution wire from the event, tick execution
‫pin to the input pin for set countdown.
‫So now what this is doing is every single frame subtracting Delta time from Countdown, taking that
‫result and setting countdown to that new value.
‫Now we can see how this behaves with a print string node.
‫So I'm going to drag off of the setter type print string and get a print string node.
‫And then I'd like to print the value of countdown so I can take the return value from the setter, which
‫will give us the new value of countdown each frame and plug it into the in string node.
‫And notice I see a convert float to string and if I release now I get a conversion node that will take
‫my float, convert it to a string, and now we can print that to the screen.
‫Now let's see what happens if I press play.
‫Check that out.
‫We see that count as being documented each frame and we're spamming the screen with the value of countdown
‫and it's getting more and more negative.
‫So this is the first step to getting our countdown timer working.
‫I'm going to close this now.
‫We saw that we're printing a float value which has a bunch of decimal points.
‫And once we print the value to the screen, we don't really want decimal points, we'd like an integer.
‫So I'd like to see the amount of seconds left without those trailing digits to the right of the decimal
‫point.
‫So what I need is an integer.
‫Well, what I can do is I'm going to delete this conversion node and I'm going to take the result of
‫the countdown setter and I'm going to type C E I'll seal, which is short for sealing.
‫The sealing operation is going to take a float value and round it up to the nearest integer.
‫So if we're at three, well, there's no need to round.
‫It's going to return an integer with a value three.
‫But if we're at 2.9, for example, then the seal node is going to round it up to three.
‫And as that value decreases, it's going to continue returning three until we get down to two.
‫So we're always going to get an integer.
‫Now I can plug this into print string and you'll see that it says Convert integer to string.
‫So now the seal node is taking a float, rounding it up to the nearest integer and returning that integer
‫value.
‫So now if I hit play, we'll see that we get 3 to 1 and zero.
‫And of course it continues going down because we never tell this to actually stop.
‫But this is a great start because now we have access to the number of seconds left and we can print
‫something to the screen in response.
‫So how are we going to print the correct message to the screen?
‫What I'd like to do is when we have 3 seconds left, I'd like the widget to say, Get ready.
‫When we have 2 seconds left, I'd like you to show the number two.
‫When we have one second left, I'd like to show the number one.
‫And when we have 0 seconds left, I'd like the text to say Go.
‫Well, we can do this with a switch node switch nodes can switch on a number of different types, including
‫INT.
‫Now the way that a switch on int node works is it has a number of cases for a number of values.
‫And based on the value that we pass into this switch node, it will do one of a number of things.
‫For example, if we pass in the integer value three, then we get the three case which will result in
‫thing three being carried out.
‫So the switch on end node has multiple lines of execution and it will only execute one of them based
‫on.
‫The input.
‫Now we can use a switch on int node and pass in an integer for example the result of our seal node.
‫So I'm going to remove the print string and I'm going to drag off of the countdown node and type switch
‫on INT and select switch on int.
‫Now notice it takes a input of type integer.
‫I'm going to pass in the return value from the seal node and also notice that we have an add pin option.
‫If we click on that, you'll see that we get a default pin in addition to the output that says zero.
‫What this says is if we hook up some blueprint logic from the zero execution pin, then that logic will
‫be executed.
‫If the input value passed in is zero, and if it's not well, then it will default to this execution
‫pin.
‫Now we can click add pin again and now we have zero and one.
‫So we can have two lines of execution, one for zero and one for one.
‫And then if the input is not zero or one, then whatever's hooked up to default will be executed.
‫I'm going to click plus again two more times.
‫So we have cases zero through three and a default case.
‫So now it's up to us to drag off of this and add some blueprint logic that we would like executed based
‫on the value passed in that we're getting from this SEAL node.
‫And that's what I'd like you to do for your challenge.
‫I'd like you to print different messages for each case using a print string node for the value three
‫you can print get ready using a print string node.
‫For the two case, you can simply print the value two for the one case, you can print one and for the
‫zero case you can print go now for the default case, simply print start game with our print string
‫node.
‫Pause the video and add a whole bunch of print string nodes in the event graph now.
‫Okay.
‫So I'd like to go ahead and use a print string node and I'm going to start down here at the bottom for
‫the default case and I'm going to type print string.
‫And the string I'd like to print is start game.
‫Now, here's a shortcut.
‫If you didn't know with the print string node selected, I can hover my mouse somewhere else in the
‫event graph and hit control dx and that will copy the node that I had selected.
‫I'm going to hook up the three case to this print string node and I'm going to type get ready.
‫So when the input to the switch is three, we'll see.
‫Get ready, printed to the screen.
‫Now I'm going to control DX again and hook this up to the two case and for two I'm simply going to print
‫two now I'm going to copy the print string node and for one, I'm going to print the value one.
‫And finally, one last print string node here is going to be hooked up to the zero case and this is
‫going to say go.
‫Okay.
‫So let's go ahead and compile this and I'm going to hit play and now I see get ready, two, one and
‫go.
‫And then of course we see start game once we've ran out of time.
‫So we know that the value is decreasing and becoming more and more negative, but that is the default
‫case for our switch and that's when we know we can actually start the game.
‫So this is the first step to showing our countdown timer in our widget.
‫We're not quite changing the text that says Get ready just yet, but we'll be doing that soon.
‫So in this video we created Countdown Logic and added that to our widget blueprint.
‫We used print string to show our countdown values and print a different message.
‫Based on our countdown values.
‫We still need to set the text in the widget, and we're going to do that in the next video.
‫I'll see you soon.