How can I use a delay or a sleep in C++?

This was your problem:

while (endTime > startTime)
{
   startTime = ()->TimeSeconds;
}

This loop completely locks up a whole CPU core/thread until startTime = endTime. That thread can do nothing except call ()->TimeSeconds; In fact, it might even be blocking Unreal Engine from updating TimeSeconds until the loop ends (which it won’t if TimeSeconds doesn’t change because it’s waiting for the loop to end so it gets its turn on the CPU – infinite loop).

What you really want is to check to see if ()->TimeSeconds >= endTime but, if it’s not, sleep your code for a bit and check later.

That’s where timers come in. No loops, just execute once, let other code run, execute your function once more, let more code run, etc.