Project keeps crashing on start and I don't see why I'd expect different

I think I must have missed something with this lecture because it doesn’t make sense to me. The problem was that an instance of OpenDoor existed in the scene and didn’t have a trigger volume assigned, and this gave a null pointer error that made the project crash on start.

I went ahead and added the following “if” statement to BeginPlay()

if (!PressurePlate)
	{
		UE_LOG(LogTemp, Error, TEXT("%s has the open door component on it but no pressure plate set."), *GetOwner()->GetName());
	}

So on BeginPlay(), my script would now check to see if there’s a pressure plate there or not. However, despite doing this check (or trying to), I still have the original problem that I haven’t assigned a trigger volume to PressurePlate, so obviously my project is still going to crash just like before, which is what happens.

I can’t work out why it isn’t happening to you in your video, because surely you also still don’t have a pressure plate assigned, so why does your project not still crash? What I see in the video is that your Editor window doesn’t crash, and you get two clear red error messages telling you about the missing trigger volume. In comparison, my whole editor goes down.

Edit: I can find the error message in the log file stored in my project folder at BuildingEscape\Saved\Logs, but this is a black and white text file and it’s going to be really difficult trying to sort through something like that the find errors.

I figured out how to get this working, but I still have almost the same question.

I hadn’t included the earlier part of the fix, but I’ve now made the following edit:

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

	if (PressurePlate && PressurePlate->IsOverlappingActor(ActorThatOpens))
	{
		OpenDoor(DeltaTime);
	}
}

My question is why making that check stops my project from crashing, as I said above, I’m now checking for the plate every frame, sure, but I still don’t have anything assigned to PressurePlate, so why does it not still crash?

Also, what does checking this in TickComponent do that checking in BeginPlay doesn’t? Why does it need to be done every frame?

Ah I had the same problem and in my understanding
In

You’re checking if PressurePlate exists and if it does, run the following code. Without this check you’d be asking unreal to just check if something is overlapping with PressurePlate ( which hasn’t been set yet) so it ends up throwing unexpected errors.

The check in BeginPlay is done for logging purposes, but we are actually using PressurePlate in TickComponent and hence we need to run the check along with it.

1 Like

C++ has short-circuit evaluation.

A && B

If A is false then B isn’t evaluated as the result of the expression is already known to be false, it doesn’t matter what B evaluates to. With that code it prevents PressurePlate from being dereferenced if it is nullptr.


Similarly this also happens with or.

A || B

If A is true then B isn’t evaluated as the result is known to be true.

1 Like

Thanks for the above replies, what I understand now is that PressurePlate is just a pointer to an ATriggerVolume-shaped memory address, and the crash only happens if the computer tries to access whatever’s there and fails to find an ATriggerVolume.

Also, knowing about the short-circuit evaluation is good, I hadn’t really understood that, and why the order of the things in the if() statement is important.

That explains a slightly different situation (pointing to invalid memory) e.g.

int* ptr;
{
    int a = 10;
    ptr = &a;
} // a destroyed here; ptr still points to that memory address.
int b = *ptr; // bad times

The issue presented in this thread is that PressurePlate doesn’t point to any address.

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

Privacy & Terms