Where is the actual Delay code?

The code doesn’t make any logical sense to me. How is it actually delaying to close the door? Where is the actual delay?

All the if statement says is that if the time you leave is greater than 1.0f, then close the door. No where in the actual code does it say to delay the door closing.

I’ve been stuck trying to figure out where the actual delay is for hours. The CloseDoor(); method doesn’t have a delay in it, just an angle to close at. So where is the actual delay? How does it know to delay closing the door?

In Blueprints, you can set a simple Delay node and this is done in 5 seconds. But I don’t see where the actual delay code is for c++. All I see is that the time is > the other time, so close the door. There’s no actual delay in that though.

Example:

if(GetWorld()->GetTimeSeconds() - LastDoorOpenTime > DoorCloseDelay) //
{
// shouldn’t there be code right here that says to delay for 1 second?
CloseDoor();
}

This is the delay. LastDoorOpenTime is being stored, think about it step by step, second by second. So lets say you just started the game the door is closed, after just over 1 second the if statement is now true
( 1.1f - 0 > 1.f)
and CloseDoor() is called, but since it’s already in the closed state nothing should appear to be different.

You now step into the volume at 2 seconds in and LastDoorOpenTime gets set to 2. You now leave almost immediately (say at 2.2). The if statement now will read
2.2f - 2.2f > 1.f | (0 > 1)
2.3f - 2.2f > 1.f | (0.1 > 1)

3.1f - 2.2f > 1.f | (0.9 > 1)
3.2f - 2.2f > 1.f | (1 > 1)

and then finally after that, that statement is no longer false and the DoorClose function is called.

Yeah I finally understand it now that its counting at every tick/frame. Obviously this isn’t the best way to do this but I remember that he said he’ll be changing it later in the series.

I’m brand new to programming so currently much of the code he’s going over is way over my head at this point. I’m completely lost in every single challenge lol I don’t even bother trying to do them anymore as I just want to learn and staring at the screen with zero clue what to do is a waste of my time.

But I understand that it’s hard to teach Unreal c++ so I’m just going to go through the whole course and hope I understand some of it by the end.

Don’t worry I just sat down with my wife to talk to her about it as she’s a math person.

I ended up writing a little bit of code to print it to the console and I read about some of the stuff on the UE4 wiki pages.

I finally got how it all worked, not as clear when you’re new to the UE4 way of things :slight_smile:

Thank you so much. You’re a good person.

1 Like

Privacy & Terms