Hey,
So these last few days I’ve been studying the architecture of Unreal Engine 4. Then, today I made a simple static camera functionality. Basically, I wanted a static camera that is not in any way related to the player. The camera just looks at the player running around. To do this, I created an actor class that you can basically spawn in the level editor, which has a property exposed where you can reference a camera in the scene as the “main camera”. The source code for this actor is simply this:
void ACameraSetup::BeginPlay()
{
UWorld* currentWorld = ();
if (currentWorld)
{
APlayerController* currentPlayerController = currentWorld->GetFirstPlayerController();
currentPlayerController->SetViewTarget(MainCamera);
}
}
On BeginPlay(), the actor tracks down the used player controller and sets the view target to “MainCamera”, which is the property exposed to the editor.
I found that through the “UWorld” class, I could get the player controller and set the view target through there. This approach works quite nicely actually. Gets the job done.
However, I went to try and find documentation on the “UWorld” class, but I can’t seem to find any specific description of the purpose of the class? I even went on GitHub to try and see if the source code had more documentation, but it didn’t.
So, is the approach I’m using actually acceptable? I mean it solves the problem, but is there better approaches through the Unreal Engine 4 workflow? And, of course, what exactly is the purpose of UWorld?
Thank you all!