Hi there, I have created a new function to toggle the visibility of an actor class. But it failed to toggle one or two actors off and on sometimes, even though I have used a while loop. can someone help me?
Below is my code:
void UMyBlueprintFunctionLibrary::ToggleWalkerOnAndOff(TArray<ACharacter*> Walkers)
{
for (auto& Walker : Walkers)
{
bool Visibility1 = true;
bool Visibility2 = true;
while (Visibility1 == Visibility2) // make sure that the targeted actor is toggled once
{
Visibility1 = Walker->GetMesh()->IsVisible();
Walker->GetMesh()->ToggleVisibility();
Visibility2 = Walker->GetMesh()->IsVisible();
}
Walker->SetActorEnableCollision(true);
}
}