After creating the blue print doors the app crashed when i tried to run it. I checked the logs and I didnt find any clues. Eventually after checking all my pointers i made this change:
for (const auto& Actor : OverlappingActors)
{
if (!Actor) continue; // ADDED THIS
TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
}
Adding the continue. This corrected the issue but i wanted to know why? Why would there me a null or invalid pointer added to the collection? Keep in mind it crashed on load, nothing is on the PressurePlate yet
This line has the potential to crash. What if FindComponentByClass failed to find a UPrimitiveComponent? It would return nullptr and then you would be dereferencing it.