Download

Timer-based game over

This feels like it should be such a simple thing, but I’ve been looking for about 3 hours all over google and YouTube, and I cannot find an answer to seemingly a simple question. I have an in-game timer in my project, and I want the player to be “killed” and booted from the game (I don’t have a game over screen, this is just a school project), but for the love of god, I cannot figure out how to do it. I feel like it should be simple:

if (CurrentTime <= 0)
{

}

I imagine there’s a function to end the game, and I was looking and found EndPlay, but when I try to fill the parameter with something like “Out of time”, it gives an error that the parameter can’t be filled by characters. I’m assuming this is what I’m looking for, and I’m so close, but I can’t get the function to work. The specific parameter it’s looking for is:

const EEndPlayReason::Type EndPlayReason

You have two options: Timers or Tick.
I recommend using Tick if you don’t know how to setup timers.
Have a FLOAT variable in your GameMode (or GameState or Controller) called “remainingTime” and set it to your desired Amount of Time.
In your GameMode’s Tick, you simply subtract Delta from your remainingTime. When remainiing Time is <= 0, your time is over.

There are already timer variables exposed in AGameMode and AGameState, and ShooterGame shows you how to use them to end the match after a period of time. I suggest downloading the example from the Learn tab and exploring it.

I thought I said I had a timer already in my tick function, but clearly I forgot to. But yea, I have the tick timer, I just don’t know how to actually end the game itself.

I’ll look into those, you said they’re from the learn tab, so I’ll look into it today. Thank you.

There’s no built-in way to end the game (other than called EndMatch or something to that effect) - you have to handle what “end game” actually means and what it does.

Ill see what I can figure out. By the way, not sure how, but somehow my quotes got flipped between when I wrote my last post and when it was posted… not sure how I did that but I was on my phone when it happened so… not totally surprising.