Why would this crash the code?

I’m missing the obvious…please point it out :slightly_smiling_face:

PressurePlate->GetOverlappingActors(OUT OverlappingActors);
for (const auto* Actor : OverlappingActors)
{
TotalMass += Actor->FindComponentByClass()->GetMass();
/* This crashed the code */
UE_LOG(LogTemp, Warning, TEXT("%s on plate, total mass is: %s kg"), *Actor->GetName(), TotalMass);
}

Hi,

I patched your code.

It should look like this:

for (const auto* Actor : OverlappingActors)
{
TotalMass += Actor->FindComponentByClass()->GetMass();
/* This crashed the code */
UE_LOG(LogTemp, Warning, TEXT("%s on plate, total mass is: %f kg"), *Actor->GetName(), TotalMass);
}

First things first:

TotalMass += Actor->FindComponentByClass()->GetMass();

In here you have to specify for what type of components you are looking for. In this case it will be UPrimitiveComponent.

The reason it crashed was you wanted to print string while you were giving UE_LOG a float.

Hope it helps!

1 Like

Privacy & Terms