TArray implementation crashes Unreal at Play

After adding the

float UOpenDoor::GetTotalMassOfActorsOnPlate()
{
float TotalMass = 60.0f;

// Find all the overlapping actors
TArray<AActor*> OverlappingActors;
PressurePlate->GetOverlappingActors(OUT OverlappingActors);

for (const auto* Actor : OverlappingActors)
{
	TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
}
return TotalMass;

}

Unreal crashes when I hit play. I did go back to a previous sourcetree save and got back to this part to a crash again.

I also saw that Actor is undefined and assuming this is the issue?

PressurePlate is probably nullptr.

Perhaps I’m misunderstanding buuuuuut

I do have PressurePlate defined in the .h file

    UPROPERTY(EditAnywhere)
ATriggerVolume* PressurePlate;

“PressurePlate is probably nullptr” I understand as my PressurePlate pointer has not been initialized and points to nothing.

If thats the case then I’m confused about how to initialize it as PressurePlate is recognized as ATriggerVolume in the .h file.

You would set what it points to in the UE4 editor on the component.

So I’ve re-watched several videos in case I had missed something but came out empty handed. The only component I can think of is the OpenDoor component which has the PressurePlate set to TriggerVolume. (Since we deleted the ActorThatOpens component).

Am I looking in the wrong area?

So you have the PressurePlate set to a TriggerVolume? On all OpenDoor components?

Yes both doors and their PressurePlate via OpenDoor components are set to TriggerVolume. Here is a screenshot only showing one door of course but both are set the same way.

I deleted the TArray lines of code and reverted it back to a hard code of ’ return 80.0f ’ to prevent unreal from crashing for the time being.

I deleted all my files saved, source, intermediate, .vs, binaries files and had unreal rebuild them. Implemented the TArray code and crash again.
Here is a .zip file of my game files before I implemented the TArray code (With the folders mentioned above deleted).

Any further guidance on this issue?

DanM,

After going through lesson 91 and adding the warning text for pointers I discovered that my skysphere had a open door component on it. Not sure how or when I accidentally did that…

Anyway after removing that component my game no longer crashes as the issue was that particular component did not have a triggervolume set.

I do have to say though it would of been appreciated if I was pointed to that lesson instead of waiting for a reply 12+ days ago.

Privacy & Terms