UE4 CRASHING solution

After 30 mins of looking around, I found out why it was crashing everytime.
Add another check to see if your “PressurePlate” is a nullptr or not…

float UOpenDoor::TotalMassOfActors() const
{
	float TotalMass = 0.f;

	TArray<AActor*> OverlappingActors;
	
	if (PressurePlate)
	{
		PressurePlate->GetOverlappingActors(OverlappingActors);

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

	return TotalMass;
}
3 Likes

Great job figuring it out! :100:

1 Like

Having the same problem - 12 months later! Unreal has just crashed for the 4th time - @DanM

I figured that was the problem after the 3rd time Unreal crashed but I had to step through what I had done. It was working up until I put the Array into play. Unfortunately, I did that at 1.30 am, compiled and didn’t test it, forgot about it, and this morning trying to fix it. I haven’t yet tried to put the if Pressure Plate back in as I have to wait for the shaders to compile every time I load Unreal (don’t ask) and the actual compile times can be minute(s).

Thanks for posting - up until I saw your message I thought I was the only one having problems.

Regards.

Can confirm categorically that this is the problem and after all the effort he went to telling us to watch out for null pointers and this happens. I knew this was going to cause problems but I followed his example because the Array threw me for a loop and because I wanted to have the same code as the lecturer. I should’ve followed my instincts in this case :expressionless:

1 Like

Privacy & Terms