TotalMassOfActors() crushes the game

HI!
In lecture 125 we build function TotalMassOfActors(), and when I use it in TickComponnent(…) the game crushes. I found out that if I remove the line “PressurePlate->GetOverlappingActors(OUT OverlappingActors);” it doesn’t crush, but obviously function is useless…
My code is:

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

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

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

	return TotalMass;
}

I found out that the problem is that PressurePlate in “nullptr” in run time, how can I change it ?

I think I fixed that issue:
I don’t know why, but I when I call this func each frame, there are frames that return nullptr to PressurePlate.
Easy fix:

if (!PressurePlate) {return 0.f;}

But again, I cannot understand why there are frames that PressurePlate is nullptr…

That would imply you didn’t set the pressureplate in the editor.

Privacy & Terms