How to ADD TIME to a countdown timer widget whenever a bullet hits NPC Enemy?

Hello there!

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:

When the timer gets to zero minutes and seconds, the game ends and loads the game over screen. All this works great.

What I want to know is: How can I get the time left on my countdown timer to increase by ten seconds when my bullet hits the NPC enemy?

Could I put it in here, inside the bullet blueprint perhaps?

The countdown stuff is here, in the camera BP - this was the only place I could get it to work:

Here are all the rest of the bits that make up the timer widget:

Any help with this would be appreciated - I just know it can’t be that hard!

1 Like

You can use variables of type:

Date Time and Time Span like this:

image

image

Then when you start you can initialize values like this:

NOW node returns current time and date.

To know the remaining time you can do something like this:

Date Time types just store that…times and dates (for example 2022/march/14/17/54/…)
Timespan types stores a time lapse(days/hours/mins/seconds/mil)

You can add extra time doing something like this:

Hope it helps! :slightly_smiling_face:

Dany

Thank you for the epic reply!

So do I create these variables in the same place I have created the variables for my already existing timer, which is in the Camera BP?


Or should I be making them in some other BP, like the bullet BP?

Thanks again for your time!

2 Likes

I use to communicate blueprints via Gamemode.

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.

Hope you know how to use dispatchers and gamemode :slight_smile:

Exactly what I needed to know!
I will bone up on dispatchers and give all this a good go… and hit you back with hopefully happy results :slight_smile:

1 Like
  1. have your own Gamemode BP and use it in your map

image

image

  1. add a dispatcher in your gamemode

image

  1. bind your camera BP to the dispatcher to a custom event like this:

*you can also bind to a function instead using ‘create event’ like this:

  1. in the bullet BP…when you want to trigger the function of the camera, just call the dispatcher from gamemode like this:

good luck :slight_smile:
Dany

Thanks heaps for your help Dany,

It’s all a bit confusing, I am very noob at this stuff - might it be easier to pay someone on fiverr or something a few bucks to fix it?

I will persist with this and let you know how i go!
Thanks again!!

1 Like

So for anyone interested, here is a solution that works:

since our camera is the actor that spawns the timer, we reference the camera in every NPC that is spawned. we only do this once using EventBeginplay.


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.

if it is greater than 60, we deduct 60 from the result and add that 1 minute to minutes, and set the resulting amount as seconds.

Now the timer works for one NPC enemy. Yay!

Now I just have to figure out how to make the same timer increase happen in other NPC enemies which I think is not happening because of this piece:

But yay progress!

1 Like

I’m sure Dany’s setup would work better but it was sadly beyond my noob level skills <3