Door opens immediately when I hit play...?

Ok everything has been great until now and everything was working fine until I replaced my magic numbers per this lecture. Now, when I hit “Play”, the door opens even though my game pawn (me) is not in the trigger volume (aka PressurePlate). It’s opening immediately. I did not change the close/if statement in UOpenDoor::TickComponent. Like I said, before this lecture everything was spot on.

I’m taking this course as a refresher - I have some prior experience in C++ and with Unreal… it’s this kind of thing that drives me nuts. I obviously changed something, but cannot for the life of me figure out what…!

Can you post your code?

Here’s the offending function. I tried a few things… I commented out everything within the if statement, and the door did not open when I hit play. I uncommented and then the door opens. So that if statement is evaluating to true and I’m having a hard time figuring out how to debug why. Yes, a PressurePlate exists. But when I hit play, my pawn is no where near the pressureplate, so the second part of that if statement should be false…

Could I have done something accidentally in the UE4 GUI…? Clicked on something that would override this or force that condition to be true?

// Called every frame

void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)

{

    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

    if (PressurePlate && PressurePlate->IsOverlappingActor(ActorThatOpened))

    {

        OpenDoor(DeltaTime);

        // DoorLastOpened = When the door was opened

        DoorLastOpened = GetWorld()->GetTimeSeconds();

    } 

    else

    {

        // if the door has been open longer than DoorCloseDelay seconds 

        if (GetWorld()->GetTimeSeconds() - DoorLastOpened > DoorClosedDelay)

        {

            CloseDoor(DeltaTime);

        }

    }

}

Have you tried adding logs to see why that might be happening? e.g.

Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

if (PressurePlate && PressurePlate->IsOverlappingActor(ActorThatOpened))
{
    UE_LOG(LogTemp, Warning, TEXT("%s is overlapping %s"), *ActorThatOpened->GetName(), *GetOwner()->GetName())
    OpenDoor(DeltaTime);
    // DoorLastOpened = When the door was opened
    DoorLastOpened = GetWorld()->GetTimeSeconds();
} 
else
{
    UE_LOG(LogTemp, Warning, TEXT("%s is not overlapping %s"), *ActorThatOpened->GetName(), *GetOwner()->GetName())
    // if the door has been open longer than DoorCloseDelay seconds 
    if (GetWorld()->GetTimeSeconds() - DoorLastOpened > DoorClosedDelay)
    {
        CloseDoor(DeltaTime);
    }
}

Oy thank you. Through an increasing series of UE_LOGs, I figured out where I made a mistake. When I was make the improvements in this lecture, and replaced the magic numbers in both the OpenDoor and CloseDoor functions, I replaced the second parameter of the FMath::Lerp in both places with “OpenAngle”… So my CloseDoor function was also opening my door.

Yes. Log messages. I’ve been programming a long time, I should know that. :slight_smile:

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms