PressurePlate crashing the engine?

Hey, I’m fairly new to C++ and unreal and I wanted some clarification on the GetTotalMassOfActorOnPlate().
In the end of lecture 90 and after changing the & to a * I found that the game would crash soon as I hit play. So I looked around here and could not find a clear answer. Someone brought up that PressurePlate needed to be initialized so after looking around in UE I realized that it PressurePlate should be initialized to TriggerVolume when Play is created. After watching some videos that Epic made I found out that the if statement will check if a pointer = nullptr so I just thought -“well what’s the worst if it runs the code and still crashes that sucks or it just doesn’t read the objects mass but atleast it would run”. Anyways, after putting the if statement to include the TArray and the calling of the PressurePlate the game did not crash and it would read the mass.

SO my question is why would the PressurePlate crash the game when staring the game since it should have already checked what PressurePlate is before calling to is as a nullptr.
Also I am not sure why we call it every tick instead of calling it on a overlap event… Or maybe that’s the same thing…

Anyways here is a picture of what the code looks like after fixing the crash

4 Likes

I ended up having to do this as well, but in my case, unreal was crashing only as soon as I triggered the triggervolume, which is weird because I think it would’ve made more sense for it to crash as soon as I hit play given that it’s a runtime error rather than a compile error? (Not sure when you would’ve rather have it crash)

To answer your question, I think the PressurePlate was already initialized as the Trigger volume placed in unreal editor and the crash was being caused by the functions being called on the empty Actors in the for loop… is what I would guess anyways.

I was thinking that adding if (PressurePlate) would check if the trigger volume in the editor was empty or not. Could be wrong, but hey it works.

Also, it didn’t matter for me whether the auto type was a reference or a pointer. Both worked the same.

EDIT: Point Protection Process lecture goes over this if anyone wants to go over that lecture first, after this one.

Privacy & Terms