Can't Name Controller Differently?

For my “for” loop, I had

for (AShooterAIController* AIController : TActorRange<AShooterAIController>(GetWorld()))
    {
        if (!AIController->IsDead())
        {
            return;
        }
    }

but it wasn’t working. I had to rename AIController to Controller to get it to work. I thought that the for loop was creating a variable for that loop only, and I didn’t think that it referenced the Controller in EndGame() at all.

Could anyone explain to me why/how it’s doing that? Thanks.

If you have a variable named AIController that could be accessed in the same scope, then that one in the loop will shadow it. Unreal has made the variable shaowing warning treated as an error in 4.24 ( or maybe 4.25 I forget).

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms