I have cam1 to cam 5 in my level. What is the correct way of collecting all the CameraActors in the game in an array using c++ except for the default CameraActor which appears when game starts?
Is it something like?
TArray Cameras;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ACameraActor(?), Cameras);
or
for (TActorIterator Itr(GetWorld()); Itr; ++Itr)
{
if (Itr->ActorHasTag(“CustomCamera”))
{
}
}
I get errors when use both in MyPlayerController.cpp.
Hello!
Use ue4 iterators , include EngineUtils.h header
TArray ^ACameraActor^ Cameras ;
for (TActorIterator^ACameraActor^ It(GetWorld()); It; ++It)
Cameras.Add(*It) ;
^ACamera… ==>template type
Sorry for bad writing.
Hope it helps!
Hi, thanks for the reply. It doesnt seem to work. I dont get to print UE_Log Iterator. And I need a way to exclude default camera actor which creates on starting the level.
TArray<ACameraActor*> Cameras;
for (TActorIterator<ACameraActor> Itr(GetWorld()); Itr; ++Itr)
{
Cameras.Add(*Itr);
UE_LOG(LogTemp, Warning, TEXT("MyPlayerController_Iterator"));
UE_LOG(LogTemp, Warning, TEXT("MyPlayerController_Iterator2 %s"), *Itr->GetName());
Mmm… I think. *itr-> … Is not correct. Use just itr->…
TArray<ACameraActor*> Cameras;
for (TActorIterator Itr(GetWorld()); Itr; ++Itr)
{
Cameras.Add(*Itr);
UE_LOG(LogTemp, Warning, TEXT(“MyPlayerController_Iterator”));
UE_LOG(LogTemp, Warning, TEXT(“MyPlayerController_Iterator2 %s”), *Itr->GetName());
Moved it to BeginPlay() and it worked