This tutorial will guide you through the creation of a basic framework for an iOS game using the Unreal Development Kit. I will walk through step by step the creation of your own UnrealScript classes, compiling the code, and setting up the configuration files. This framework will also be the base for future tutorials, so don’t skip this one!
To start with, we’re going to set up a few UnrealScript classes. We’ll be working in our own folder in the Development/Src directory, which for this tutorial we’ll call AwesomeGame:
For this basic framework there are only four classes that we need to create, a GameInfo which defines the rules of our game and specifies a few default classes, our own PlayerController which controls the player’s viewpoint and keyboard/mouse input among other things, a Pawn which controls how the player looks and interacts with the world, and the HUD which displays things like health, ammo and for mobile games also displays the thumbsticks used to control the character.
Create a new text file in the AwesomeGame/Classes directory and name it AwesomeMobileGame.uc (make sure you have file extensions enabled in Windows so you don’t accidentally name it AwesomeGame.uc.txt). In this class we will specify which PlayerController, Pawn and HUD class our game uses. We only need a few lines of code for this, all of them in the default properties:
Now that our classes are specified, let’s create them. We’ll start with the PlayerController class, which I’ve named AwesomeMobilePC. Create a new text file called AwesomeMobilePC.uc. We’re going to put a line of debug code in this class so we know that it’s working:
PostBeginPlay is a function that is run on all Actor classes when they’re first created. Calling super.PostBeginPlay makes sure that any code higher up in the class tree is run (in this case since we’re extending from MobilePC, it will make sure that MobilePC’s PostBeginPlay is run to do any setup it needs to do). The `log macro simply outputs text to the log file when it is called.
Now let’s do the same with our Pawn class. Create a new text file called AwesomeMobilePawn.uc:
And to our HUD class. Create a new text file called AwesomeMobileHUD:
You should now have four files in Development\Src\AwesomeGame\Classes: AwesomeMobileGame.uc, AwesomeMobilePC.uc, AwesomeMobilePawn.uc and AwesomeMobileHUD.uc. Now that our classes are created, we need to compile them into a .u file so the game can use it. To do this we need to add a line to MobileGame\Config\DefaultEngine.ini. The fourth section of this file should have the header [UnrealEd.EditorEngine]. We need to add our line at the end of the EditPackages list:
The name AwesomeGame comes from the folder that our files are in, this will be the compiled file’s name. It is important to add our package name to the end so that Epic’s code is compiled before ours, otherwise the classes that we extend from may not be compiled before ours is and we will get compiler errors saying the classes are missing.
Now we can compile our code. There are a few ways of doing this, but to keep it simple for now we’re simply going to run UnrealEd. A shortcut should have been put in your Start menu when you installed the UDK, if it’s not there then go into Binaries\Win64 (or Win32 if you have a 32 bit OS) and right click UDKMobile, then click Send To, then Desktop (create shortcut). Right click the shortcut on the desktop and go to Properties. In the Target field, add “editor” to the end (without quotes), like this:
Hit Apply, then Ok. Now double click the icon to start the editor. Before it opens a message will pop up saying “Scripts are outdated. Would you like to rebuild now?” Hit Yes, and a command window will pop up and the code will be compiled. If everything is correct it should say Success at the end:
If there are any errors, double check that the classes are correct. Also read the error message closely, they’re usually self-explanatory and will point you to the file that needs fixing. Once compiled, AwesomeGame.u should show up in MobileGame\Script. This directory is where the compiled script files are kept.
We’re almost ready to run the game! Before we do that we need to tell the engine to use our AwesomeGame class as the default game. To do this we have to change a few settings in MobileGame\Config\DefaultGame.ini in the second section. Make sure the editor is closed and change the lines to this:
IMPORTANT! Any maps you make in the editor have to have their View >> World Properties >> World Info >> Game Types Supported On This Map and Game Type For PIE set to your game type (AwesomeMobileGame in this case) to make sure that the script file makes it to the iOS device. Otherwise it will default to a different game type and not behave as you expect it to.
Now we can run our game! Open the editor, and the default map SimpleCourtyard will be opened. For this test that map will be fine, so press the Mobile Previewer button to run the game:
You will spawn in the courtyard and the two thumbsticks will show up so you can move and look around. Exit the mobile previewer and close the editor. Now, in MobileGame\Logs, open Launch2.log. The reason we’re not opening Launch.log is because that file was being used by the editor itself, so the Mobile Previewer created a second log file, Launch2.log. Scroll down and we should see the debug code we added to our classes:
Don’t worry about the FacebookZone errors, for this tutorial they’re not important.
That’s it, our basic framework is complete! We will be using this for future tutorials, so hang on to the code that you’ve created!