Hi i am on lecture 88

i have read over the lterating over TArray with for, if anyone has idies plz iet me kown

fix it

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

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

// Iterate through them adding their masses
for (const auto& Actor : OverlappingActors)
{
	TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
	UE_LOG(LogTemp, Warning, TEXT("%s on pressure plate"), *Actor->GetName())
}

return TotalMass;

}

try

 for (const auto* Actor: OverlappingActors)

Ben does explain at about 3:40 in the video that he made tiny mistake with the syntax… to be strictly technical, we want a pointer to each Actor in OverlappingActors, not a direct reference. Hence *, not &

A reference instead of a pointer wouldn’t make it not compile or cause problems, it would just mean there would be a problem with the constness. As the type would be AActor* const & meaning the const is applied to the pointer and not the value the pointer points to.

Privacy & Terms