Functions with timer and condition

Hi everyone! I recently started doing more things with UE as an early extra to my programming degree.
I was trying to make a function that can be exit under to conditions, when a timer ends or when a condition is required, a boolean to make it easier. The thing is that so far and for what I’ve found around the forum I’ve managed to set the function timer with the Set Timer but I’m lost on the part of also adding the other option for the exiting when the boolean has a determined value.

Is there a way to make a function run for a certain amount of time or until a condition is met?

Thanks in advance!

I think you are looking for the node “clear and invalidate timer by handle” if you are working in blueprints. It looks like the screen shot below. Otherwise if you are using C++ when you create your timer you should save the handle and then you can call the clear and invalidate function. This is an example of a timer I created using C++ and how to invalidate/clear it.

// Create A Timer
Parent_Actor->GetWorldTimerManager().SetTimer(Universal_Age, this, &UEarthTime::AgeOfEarth, 1 / Rate, true);

// Clear Timer
Parent_Actor->GetWorldTimerManager().ClearTimer(Universal_Age);