I’m working on a really simple beat-the-clock game where the player drops bullets from the top of a building, hoping to hit an NPC enemy that roams the street below.
The game begins with a two-minute countdown timer running. If the timer reaches zero seconds, the game ends. But each time the player can hit the NPC enemy with their bullet, the timer gains ten seconds, extending the play time.
I have successfully made a working timer widget that is casting to my viewport, thus:
I have my own gamemode and then I’d just create a camera BP type variable in my gamemode.
In the beginplay of the camera blueprint I store the bP in the gamemode variable (self)
Then also a dispatcher in Gamemode like ‘extend_time’
in the bulletBP, when you want to extend the time you call ‘extend_time’ from gamemode
in the cameraBP actor you bind the ‘extend_time’ call from gamemode to your extend time function to listen when the bullet calls and just run the function.
then we set that reference as a variable to use at will.
When the NPC gets hit, we fire a custom event called “increase timer” inside the camera actor by using the object reference we made earlier.
back in the camera actor, when the custom event is fired, we do a nifty little maffs where we get the current seconds, add 15 to it, and check if the result is greater than 60 or not. if not, then we set it to current seconds value.