I would like a stronger understanding of the engines flow

Hi all, I already have some years of game dev experience, and a couple completed and published games of varying complexity(other engines). I have not been able to get as much of a grasp on Unreals structures as I would like. I have done a handful or tutorials over the years, and even had a mostly finished full project , but still did not get where I wanted with my understanding. I understand basic Actor/Component systems written in C++,(like a basic game loop-update, actors with components(meshes and input etc) the main thing I do not get is Unreals use of things:
Maps-GameModes-Player Controllers
I basically understand what a Blueprint Class is, you can create an actor or special actor with some basic functionality available, add mesh components and some scripting, this way it can be instanced into the game. But who does all the instancing and level swapping etc?

Like when you hit play, it loads the level with an attached gamemode(which is what exactly, a file with?), which knows the player controller that would be in use for the specific level.

If possible I would love a simple run down of if you made a simple platforming game. For example: A third person character goes from start of level to end, then loads into another level, meanwhile you keep track of Stars found or something.

I do understand C++ the language btw, but not all the facets of Unreal.
My guess atm is, have project settings load first map “main-menu.map”, the map has its own Player Controller and gamemode? Then you hit play btn in main menu and it goes to level 1- which uses the 3rd person Player controller and what game mode?

Assume I have made a Third Person player Blueprint that moves on my input with camera etc. Like what file would I be in to instance the character, and spawn it in a level, then at the end trigger of level this same file brings you to next level.

Thanks for the help.

First, there does exist documentation for this exact thing:

This tells you what a GameMode is.
However, in brief, here are the most important things about GameMode:

  • GameMode runs only on server (although for a single-player game, that game is the “server,” and even on a multiplayer game, a listen server runs both an interactive player, and a “server” in the same process.)
  • GameMode is responsible for spawning player Pawn instances, once a PlayerController enters the game. (The networking or single-player game setup owns actually creating the PlayerController)
  • GameMode contains code that manages most of the overall flow of “what is the game.”
  • GameMode also contains a few selectable class references, for which player Pawn class to spawn by default, which PlayerController class that the network system will use, and so on. The default implementation of spawning objects inside GameMode will use these class selections, but you can override the functions on GameMode to hard-code a class if you want, and then those popup menus will stop “working.”
  • GameMode is specified by default for the whole game in the Project Settings, but can also be specified for a particular Map in the World Settings for that Map.

In the Project Settings, there’s two Level references you can set. One is for “which level to open when I open the editor,” and one is for “which level to open when I open the built game.”

Any other level/map loading, happens through code that you write. Either blueprints, or C++. You can call the “load map” functions from your GameMode or you can call it from some level. For example, it’s common to have the first level in the game be something that just puts up a GUI, and the “Start Game” button will then open the first level map of the game.

Keeping track of overall game state, is done in the GameMode, although you’ll probably want to use some kind of SaveGame instance to save/restore between sessions.

Keeping track of per-player game state, is typically done in a PlayerState instance. Which class gets created for PlayerState, is determined by the GameMode as per above.

If you want the ability to have a level that only has menus, and no player Pawn, then you could override your GameMode class to check whether there is a PlayerStart object in the level, and if there isn’t, then don’t spawn a player Pawn, else call the inherited function to spawn the Pawn subclass specified in the popup menu. You can then make this GameMode be the default for the project, and it will work for all your maps (assuming you play as the same kind of character in all levels.)

1 Like

A little more specific information on how the gamemode is loaded:

In Unreal" everything is done by loading levels, then when a map is loaded it first looks to see if the World settings have a gamemode override.

:heavy_minus_sign::heavy_minus_sign:

if it is empty then load the gamemode that is in project settings

This gamemode should be the gameplay mode, so when you load a map without doing anything, the gameplay is already activated

:heavy_minus_sign::heavy_minus_sign:

So for the gamemenu I usually have a main scene that loads when the game starts and with the Gamemode override to a main menu gamemode

:heavy_minus_sign::heavy_minus_sign:
Finally, consider the use of inheritance in both the gamemode and the player controller

:heavy_minus_sign::heavy_minus_sign:
When you go from one map to another everything is destroyed except the gameinstance that lives for the entire game session.

So it is a good place to create the savegame, so you can access the saved data without having to load the savegame every time you go from map to map.

Thanks for info breakdown

This breakdown was very helpful, thank you, made some of the ideas click better for me. Couple questions-

  1. Are world/map/level all synonymous?
  2. Is it common to define your own game instance class for a project, it seems to be a data only blueprint? if you break down instance the same way you did for game mode and level that would be amazing.
  3. And is this correct? game instance loads the map, which in turn has a game mode connected to it (default or custom)? Game mode knows what player controller bp to spawn and other data info you can input into the fields?
  1. Map and Level are synonymous. A World is something slightly bigger - a World can load multiple Levels into it. However, for the “simple case,” it’s true that “loading a new level” also means “making a new World.”

  2. Yes, it’s pretty common to define new classes for all the different classes selected by the GameMode (and others, like various actors for gameplay, too.) Whether you have to depends largely on how complex your game is, and whether you need variation in the particular variation point of gameplay that the class in question is intended to solve.

  3. Sounds right. I haven’t actually traced through that code, so you probably know as much as me at this point :slight_smile:

I find that it helps to think “How is the gameplay of Unreal Tournament structured?” Then map the concepts in the Unreal Engine to that structure. And, while Unreal Engine can be used for many other kinds of games these days, the bones of the Unreal Engine Lifestyle are still rooted in that area…

  1. As it says jwatte (I guess I messed you up by putting “map” intead od level in my answer)
  2. Yes, The game instance can also be broken down, for example I use GI_Common → GI_InGame → GI_MyGame
  3. Roughly yes, although you can load levels from anywhere, having the load function in the game instance is fine.