Get the latest Education e-news
 
  • Test Drive the Unreal Engine

    [01.10.13]
    - Sjoerd De Jong
  • [In this reprinted article from Game Developer magazine's 2012 Game Career Guide issue, Sjoerd De Jong details the steps involved in making a simple third-person game using the Unreal Development Kit.] 

    The Unreal Engine is the tech that drives Batman: Arkham City, Borderlands 2, Mass Effect 3, the Gears of War series, and several other major games-including yours, if you'd like it to. The Unreal Development Kit (UDK) is free for individual, noncommercial use, so just download it from www.udk.com/download (Windows PCs only), and I'll walk you through the basics of making a simple third-person game in Unreal. We'll start out with the basics of installing and setting up the engine itself, then we'll introduce UnrealScript and start building your first level.


    Starting with Unreal Script

    Once you've downloaded and installed the UDK, navigate to the UDK install folder (the default folder at the time of this writing is C:/UDK/UDK-2012-05). You should see four folders in the UDK-2012-05 folder: Binaries, Development, Engine, and UDKGame. The Binaries folder contains the executables and all of the files that form the compiled engine. The Development folder contains the UnrealScript source code. The Engine folder contains the most essential content and configuration files. And the UDKGame folder contains everything else: compiled game code, levels, sounds, textures, and so on. You'll be doing most of your work in the Development and UDKGame directories-don't touch the files in Binaries and Engine for now.

    Open the Development folder and then open the Src folder. You should find 16 folders within the Src folder-these folders contain your game's source code. Note that this is not the source code of the actual Unreal Engine itself, just the code that handles the gameplay in the game. (The engine source code is off-limits for UDK developers.)

    From the Src folder, go to the UDKBase folder and open the Classes folder inside. There should be about 120 files in the Classes folder, each with a .uc extension. These files are UnrealScript source files, and they're just TXT files with a different extension, so you can open any of them in Notepad or your preferred text editor. Go ahead and look around for a minute.

    Now you're going to write your own UnrealScript and set up an UnrealScript package. Navigate back to Development/Src and create a new folder. Name the folder "MyFirstGame." Inside MyFirstGame, make another folder named "Classes." Next, create a new empty text document inside Classes by right-clicking in the folder and going to New, Text Document. Name the new text document "MyGameInfo" and change the extension from ".txt" to ".uc". (If you don't see any file extensions, go to Control Panel, Folder Options, View, and uncheck Hide extensions for known file types). Open MyGameInfo.uc in Notepad, and type the following code:

    class MyGameInfo extends UTDeathmatch;

    defaultproperties
    {

    PlayerControllerClass=class'MyPlayerController'
    DefaultPawnClass=class'MyPawn'
    Name="Default__MyGameInfo"

    }

    For our game, we're going to use MyGameInfo to hold the rules of the game. We won't go into building game rules for this tutorial, but once you're more comfortable with the UDK, you would put your win/loss conditions in here. For now, we're making our game adopt the rules found in Unreal Tournament's Deathmatch mode (specified in UTDeathmatch).

    UnrealScript is somewhat similar to Java: Files always have a header/ title at the very start of the file that identify the file by name (MyGameInfo) and specify the file's parent class (in this case, it's "UTDeathmatch"-go ahead and find the file UTDeathmatch.uc in the Development folder and see what it looks like). Children files take over all functionality of their parent files, and the parent of the parent, and so on, so you only have to write code for things that were not already covered at some point by one of the parent or grandparent files. Note that you must make sure that the file name matches the header inside the file exactly (without the extension); if you've named this file something besides MyGameInfo, you'll need to change the header, too.

    A typical UnrealScript file has the actual UnrealScript code below the header, and a section called "defaultproperties" below that which contains the default settings for the class or actor that corresponds to your file. For this file there is no actual UnrealScript code present because we're just using this file to change a few default properties.

    Make another text file in the Classes folder, name it "MyPlayerController. uc" and enter the following code in that file. Note that the bolded text is just describing what the code does-you don't need to type that in.

    /**
    * MyPlayerController - This class allows players to control pawns.
    */
    class MyPlayerController extends UTPlayerController;

    /**
    * Called when the controller should possess a pawn in the world
    *
    * @param inPawn Pawn to possess
    * @param bVehicleTransition If true, then the controller is actually possessing a vehicle

    event Possess(Pawn inPawn, bool bVehicleTransition)
    {
    // Call the parent versions of this function
    Super.Possess(inPawn, bVehicleTransition);
    // Set the camera view mode to behind view, so that we are looking behind the pawn
    SetBehindView(true);
    }

    // Default property block
    defaultproperties
    {
    }

    As you can see, we have a small amount of actual UnrealScript this time that specifies how you control and view the character.


    Listing 1

    Now make one more text file in the Classes folder, name it "MyPawn.uc" and enter the code in Listing 1 (except the bolded comments). Once you're done with that, you‘ll have the absolute bare essentials required to start building a game with the UDK, but we need to compile it into something that the engine can use in the game and in the editor. In order to do this, we must tell the Unreal Engine that our new code package exists, which means we have to change the engine's configuration files. Here's how you do it.

    First, go to UDKGame/Config, which contains all the .ini files that control how the game behaves. You can edit .ini files in a text editor, so go ahead and open one of them in Notepad.

    The Unreal Engine uses all the .ini files with "Default" in the name to generate the .ini files with "UDK" in the name. In other words, if you were to delete UDKEngine.ini, and then start the game, it would automatically re-create UDKEngine.ini based on the information it found in DefaultEngine.ini. We're going to edit the default .ini files to build our game.

    Open DefaultEngine.ini and look for the section [UnrealEd.EditorEngine]. Add this line at the bottom of that section:

    "+EditPackages=MyFirstGame".

    It should look like this:

    [UnrealEd.EditorEngine]
    +EditPackages=UTGame
    +EditPackages=UTGameContent
    +EditPackages=MyFirstGame

    "MyFirstGame" refers to the name of the folder you made in the Development folder, so if you named your folder something else, you'll need to put that name here instead.

    Next, locate the section [Engine.Script Packages] and add "+NonNativePackages=MyFirstGame" to the bottom of that section.

    For Example:

    [Engine.ScriptPackages]
    +NonNativePackages=UTGame
    +NonNativePackages=UTGameContent
    +NonNativePackages=MyFirstGame

    Save and close the .ini file, and start the editor via the Windows Start Menu shortcut. If you've done everything correctly, a dialog window will pop up that says "Scripts are outdated. Would you like to rebuild now?" Click Yes.

    After UDK has finished rebuilding the scripts, go to the UDKGame folder and open up the Script folder within. This folder contains the compiled code. Every file here corresponds to a folder in the Development folder. To verify that your new code compiled, see if you can locate the file MyFirstGame.u. If that file is there, start up the Unreal Editor again; you're ready to start building a level.

Comments

comments powered by Disqus