I’m trying to make an in-game clock for my day/night cycle, for easy testing I’ve been trying to make it take 60 seconds for a full day to pass. I’m working in Game-Days-Per-Minute for ease of use, then converting it to game-seconds-per-second for ease of calculation:
This looks right to me, but the timing doesn’t work out: if I set DayInMinutes to 1, it takes approximately three real-world seconds for one in-game minute to pass, which only works out to 20 game minutes per minute, not 1440. Is there an obvious cludge-up with my logic, or is deltatime not what I want to be using to run my clock?
It’s the modulo operator. It pretty much gives you the remainder of a division operation. The error is my bad since 60 and 24 are ints not floats. Try switching to 60.0f and 24.0f.
Cast() is an unreal cast for unreal objects like UObject or AActor or anything else that uses Unreal’s reflection system. You want to use a C style cast like this (int)totalTime.
You shouldn’t need your clockSecond/Minute/Hour to be anything other than ints, so you don’t need all your temps.
The inGameTime should probably be a float or a double too (float’s probably fine).
and then define your inGameTime as a float and all the clockSecond/Minute/Hour as ints. I’m not sure why it’s 0 without seeing more code. have you tried putting a breakpoint in there to see what it’s doing?
Ooh, thank you for the heads-up about casting, I didn’t even know that C-style casts worked in ue.
I think the all-zero thing was a weirdness in my original logic, as it’s gone away with implementing yours, but it’s still a bit weird. I yanked out everything except for the bare bones, shifted some of the stuff that didn’t need floating-point accuracy to ints, and ran it with this:
//Variable decs in the .h
int32 clockSecond=0;
int32 clockMinute=0;
int32 clockHour=0;
float inGameTime;
float totalTime;
//timekeeping function that runs every ComponentTick:
Clock second increments correctly, climbing from 0-60 at the prescribed rate and then resetting, but something weird happens with the minutes and hours: clockMinute always remains 0, and every time clockSecond goes from 60-0, clockHour will flip-flop between 0, and 12.