GameInfo, Map Association, WorldInfo, UTGame
In the UDK, the GameInfo actor is what you would think of as a game type. The GameInfo Actor is a class that designates and pulls together the various components required to form a game. This is mostly done in the defaultproperties of the class as the heavy lifting is mostly done by the GameInfo super-class itself meaning that you should not have to update the class' functionality if you just need a basic game type.
Associating a GameInfo Subclass With a Map
To use a GameInfo subclass that you've created, we must associate it with a map and then load that map. The process to do so is as follows:
- Create your GameInfo subclass and compile it
- Start the editor and open/create your map
- Open the WorldInfo properties by navigating to:
View -> World Properties
- Expand the Game Type category in the properties window
- Minimally set Default Game Type to your GameInfo subclass. Additionally, set the other properties:
Game Type For PIE
- PIE stands for: Play In Editor
- This is useful if you want to test your map with your compiled game type when you click the various play in editor buttons
- This is a useful property and should likely be set to your compiled game type
Game Types Supported On This Map
- Useful for maps that need to support multiple game types while allowing the base game info actor decide which game type to spawn dynamically
- Really only useful for maps built to work specifically with UT in order to deal with the various UT game types using the same maps. For example:
- UTDeathMatch
- UTTeamGame
- If your GameInfo subclass extends UTGame, you will need to address some complications. See the UTGame section in this document.
WorldInfo & Accessing Map's GameInfo
In any game session, there exists a single GameInfo or GameInfo-subclass actor that acts as the gameinfo for the map. It can be accessed through:
WorldInfo.Game
In this case, WorldInfo is variable of type WorldInfo that is defined on Actor as follows:
var const transient WorldInfo WorldInfo;
- Notice that the specifiers const and transient are defined here
- const implies that this property cannot be changed as it is set for you by the engine
- transient means that the value in this variable will not last past the lifetime of the current map ie when the map changes for any reason, this value is set to None
- Yes, it is possible for some actors to sometimes survive past the change of map :)
Like GameInfo, every game session has a single WorldInfo Actor that encapsulates the properties of the map itself. The WorldInfo Actor defines Game as follows:
var GameInfo Game;
When using a custom game type ie a subclass of GameInfo (as is typically the case), you will need to cast this variable to the desired class first before being able to get its properties.
WorldInfo Properties
WorldInfo also has other useful members:
var float TimeSeconds
- Time since the game began in seconds
- Affected by game speed, pauses, etc... ie NOT realtime
var float RealTimeSeconds
- Wallclock amount of time that has passed since the game began in seconds
- Unaffected by pauses, game speed, etc...
var float DeltaSeconds
- Amount of time since the last tick in seconds
- This is the value passed to every actor's Tick event
var string ComputerName
- The name of the local machine, according to the OS
Useful Functions to Call
WorldInfo also has some functions that could be useful to call:
native final function SetMusicVolume(float VolumeMultiplier);
- Sets a multiplier on the current volume of music
- Value between 0 and 1 to scale the volume
native function float GetGravityZ();
- Returns the Z component of the current world gravity
native final static function WorldInfo GetWorldInfo()
- Allows non-actor derived classes to get access to the current WorldInfo Actor
GameInfo Properties
Subclassing GameInfo or a descendant of it let's you define a new game type. Let's look at some GameInfo member variables that are useful to set in the defaultproperties:
var class<HUD> HUDType
- This is the HUD that player controller's will use when playing your game
var class<PlayerController> PlayerControllerClass
- The class of PlayerController to spawn for your game
var class<Pawn> DefaultPawnClass
- The class of Pawn to use for controllers in this game
- Selection of pawn class to spawn for controllers can be overridden in GetDefaultPlayerClass (see below)
- The class of Pawn to use for controllers in this game
var float GameSpeed
- The speed of the game as a fraction
- Defaults to 1
Useful Functions to Override
For basic games, setting the above in the defaultproperties of your game type is adequate. For more complex requirements, it can also be useful to override some of the functions defined in GameInfo. Here are some of the more important ones:
function float RatePlayerStart(PlayerStart P, byte Team, Controller Player)
- This function is called when spawning a player and is passed a PlayerStart, a team index (may not be relevant), and the player's or bot's controller Actor
- This function will be called for every player start in the map whenever a player or bot is being spawned
- You can use it to restrict at which player starts various players may start by returning 0 when a player start is inappropriate and 1.0 when the player start is desireable for that player
- For additional granularity, you may return an arbitrary float from this function. The function responsible for repeatedly calling RatePlayerStart (GameInfo.ChoosePlayerStart) will then choose the player start with the highest score to spawn the player at
function Killed( Controller Killer, Controller KilledPlayer, Pawn KilledPawn, class<DamageType> damageType )
- Called when a player or bot is killed
- Override to redefine what the game should do when a player or bot is killed
- Note that this is not the only place where you could detect a player's death but any code that must be performed for every death, regardless of the type of player/player+pawn combination that died, should be placed here
function RestartPlayer(Controller NewPlayer)
- Performs the logic required to restart a player or start the player for the first time
- Can be overridden to selectively restart players or bots based on certain conditions
- This can be done by either choosing to call the super version of this function to let the normal restart player process proceed or not calling the super version, thereby aborting the process
static event class<GameInfo> SetGameType(string MapName, string Options, string Portal)
- Should return the class of game that should be spawned for a given map name
- By default returns Default.Class
- This returns the class of the current GameInfo actor as a class object
function bool ShouldRespawn( PickupFactory Other )
- Determines whether a PickupFactory is allowed to respawn
function class<Pawn> GetDefaultPlayerClass(Controller C)
- Should return the class of Pawn to spawn for a Controller
- Defaults to DefaultPawnClass
- This function can be overridden to return different Pawn classes based on changing conditions
function StartMatch()
- Begins the match, spawns pawns, etc...
- Override to know when game play actually begins
Useful Functions to Call
You may also call some functions to perform certain tasks:
function ResetLevel()
- Restarts the game without reloading the level
function SetGameSpeed( Float T )
- Sets the speed of the game as a fraction from 0.000001 to infinity
- Game speed can also be set as a default property
function int GetNumPlayers()
- Returns the number of players and bots currently in the game
UTGame
UTGame is a prominent subclass of GameInfo that defines the properties required to start a basic game of UT. We care about this class because it makes basic testing a bit easier for us as it gives us bots that react, shoot, gives us a player controller that has guns, handles scoring in a UT game style, etc...
However, it also comes with some peculiarities. Let's look at UTGame's properties:
var class<UTBot> BotClass
- The class of controller to use for bots
- UTBot is a subclass of AIController which is the AI counterpart to PlayerController
var bool bUseClassicHUD
- Must be set to true if you want to set a custom HUD type because otherwise, UTGame will override the value you place in HUDType
var array<string> MapPrefixes;
- Array of map prefixes
- UTGame enforces a map naming convention of <Prefix>-<MapName>.udk, eg DM-Deck.udk
- UTGame uses the Prefix part to determine the type of GameInfo actor to spawn given a particular map
- This means that you have two options if you want to sub-class UTGame and have your game type be loaded (as opposed to UTGame):
- Make sure your game type's maps are named <Prefix>-<MapName>.udk then set the first element of MapPrefixes equal to whatever your map name's prefix is, ie:
MapPrefixes[0]="L1"
- Override the function SetGameType to return your game's class (ie copy the contents of this function from GameInfo) as this is where UTGame performs the prefix-based map selection
- Make sure your game type's maps are named <Prefix>-<MapName>.udk then set the first element of MapPrefixes equal to whatever your map name's prefix is, ie: