Download

Question newbie: How to access activity camera from UWorld C++?

Hello. I’m newbie UE4 I got a question “How to find out current activity Camera on UWorld?”.
I was some tries like this 1.UWorld::GetComponents, UWorld::GetCameraComponent → Kind of these not supported functions…
Where is the access key value?

Where is your Camera located. If its somewhere in the world, that means you are using ACameraActor. If that’s the case, then you can use an Actor Iterator to find it in the world.



ACameraActor *TheCamera;
for (TActorIterator<ACameraActor> ActorItr(GetWorld()); ActorItr; ++ActorItr)
{
    TheCamera = *ActorItr;
}


The link below explains more about Actor Iterators.
https://wiki.unrealengine.com/Iterat…_Faster_Search

But you should be spawning the ACameraActor in the GameMode in the BeginPlay function. Then to access it, just do UGameplayStatics::GetGameMode and cast to your game mode and access that camera actor with a getter or make it public. Then you can do whatever you want with it.

Thank you for your reply. Have a nice day.