What exactly is the purpose of UWorld?

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? :slight_smile:

Thank you all!

UWorld as name state represents the game world, not only level but also all active elements, it holds refrences to them, like player conteoller game mode etc. It like a hub to game world from which can be easilly accessed from any actor. And this wprkflow is acepptable, i mean why this could be bad to do?you getting poter to object you want ; p

Only issue i can see is this solution will only work in single player, ot better to control camera from player controller it self. Also best way to hold main camera infromation is UWorldSettings which is responcble for world settings options which state is safed in level file (it work the same way as defults in blueprint), this way you can easily set camera that is on the level.

Thank you for the answer! :slight_smile: Clears things up a bit!