How to make code trigger again?

Hello! So a super simple question, I got this “Office monster” where player has to press a button in 60 seconds after it appears, or it spawns in the office. But I’d like the monster to have a chance to appear again after button is pressed (And restart the 60 second timer)

How should I go on doing this?

Here’s the (Very experimental) code

After you clear the Timer Handle, as shown when you press the button, you need to call your timer count down again.

You already have a Set Timer by Event (Your Monster Timer Handle), that links to a Spawn Monster Function.

I’m not sure what the Whisper Spawn is for, but you should make a function like “Restart Monster Spawn Timer” that feeds into your 60s Set Timer By Event

When you pressed the button, you can just call to the “Restart Monster Spawn Timer” directly. This setup also ensures that handle is cleared every time it’s called.

You are pretty much on point with your logic.

However, you are using timers incorrectly. They can be set to trigger in a specific time period, instead of setting them looping and checking, like so:

(instead of spawning and moving, I’m just writing on screen but you get the jest)

This is your interaction in that case:

(again I’m using some debug keys to trigger it but you can use your own interaction)

Bonus: to debug what is happening:

And a bonus advice:

Try to avoid spawning and destroying actors runtime. These are ones of the most costly operations. Hide and disable instead of destroying and move/teleport and enable instead of spawning.

Alright thanks a lot for the help! I just have one problem, where even if I press the button, the “Whisper monster” won’t disappear and the countdown won’t restart, I took these screenshots if you guys happened to know the fix!

I appreciate the support!

[Before spawning in office]

[After spawning in the office]

The reason it is not disappearing is because you are not hiding it when you press the button.

Your countdown should be restarting but I don’t see any way to tell if it does. Please implement the debug blueprint and try again.

Alright thank you! So the timer does work, it starts, takes 60 seconds for the monster to appear in the wall, and another 60 seconds for monster to appear in the office, though after doing some testing, the button simply doesn’t reset the timer.

If you guys have any idea on why that is, I’d appreciate it a lot!

Button:

This should be your Button blueprint:

The button blueprint you’ve show does not “Clear and Invalidate Timer by Handle” and so the timer is not cleared and invalidated.