Download

Waypoint is undefined

I get Waypoint is undefined error when trying to compile


for (AWaypoint* Waypoint : TActorRange<AWaypoint>(GetWorld()));
{
bool IsInWaypoint = Waypoint->AllowedAccess.Contains(OwnerCharacter);

if (IsInWaypoint == true)
{
UE_LOG(LogTemp, Error, TEXT("Waypoint found"));
}
else
{
UE_LOG(LogTemp, Error, TEXT("Waypoint not found"));
}

}

Please help

You have a semicolon after the for-loop’s parenthesis. What the compiler sees is this:



for (AWaypoint* Waypoint : TActorRange<AWaypoint>(GetWorld()))
{
//Empty block(the set of curly brackets) is provided since you didn't provide one before ending your statement(the semicolon)
//Waypoint valid in this scope because it's defined in the for-loop's initializer
}
{
//Waypoint not valid in this scope because it was not declare or defined in this block or the outer scope
bool IsInWaypoint = Waypoint->AllowedAccess.Contains(OwnerCharacter);

if (IsInWaypoint == true)
{
UE_LOG(LogTemp, Error, TEXT("Waypoint found"));
}
else
{
UE_LOG(LogTemp, Error, TEXT("Waypoint not found"));
}

}

Delete the semicolon in the first line and it should compile.

Thank you.