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:

 

UnrealScript directory setup

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!

Download the source files for this tutorial.

9 Responses to “Creating a Framework for a Basic iOS Game”

  1. Geta-Ve says:

    Awesome! I just got through with this tutorial and it has helped immensely! :)

  2. Tinkerer says:

    Fantastic tutorial!

    Keep up the great work! :)

  3. gamers forum says:

    gamers forum…

    [...]Creating a Framework for a Basic iOS Game « Stubborn Horse[...]…

  4. Tyler says:

    Hi, I’m using the Dec 2011 UDK release and I think that the way UDK handles mobile game packages has changed. Firstly, there is no “UDKMobile.exe” only a UDK.exe

    And there is no “MobileGame\Config\DefaultEngine.ini”

    The entire MobileGame structure of UDK seems to be removed. I tried adding my AwesomeGame package to the UDKGame\Config\DefaultEnging.ini but I am getting an error when I compile.

    “Error, Superclass MobileGame of class AwesomeMobileGame not found”
    for the 2 other classes as well.

    It seems that they have removed the MobileGame package altogether and are now calling it something else…

    Or I’ve just screwed up completely.

    Any ideas?

    • Rachel says:

      Ah wonderful, looks like I’m going to have to redo all of these tutorials. I haven’t had a chance to look at the December UDK yet, I’ll update the tutorials when I do. Thanks for letting me know!

  5. Tyler says:

    Aha!

    They made the changes in the June update:

    “In the June 2011 UDK Beta, the MobileGame and UDKGame directories, executables, etc. have all been merged into a single content path and workflow. This makes it much easier to develop projects across platforms, but it means that existing projects will have to make some changes in order to function properly.

    Relocate custom content packages from MobileGame\Content directory into the UDKGame\Content directory.
    Relocated maps from MobileGame\Content\Maps to UDKGame\Content\Maps and change the extension to .udk from .mobile.
    Merge changes in MobileGame\Config .ini files into UDKGame\Config\Mobile .ini files. Specifically:
    MobileGame\Config\DefaultEngine.ini -> UDKGame\Config\Mobile\MobileEngine.ini
    MobileGame\Config\DefaultGame.ini -> UDKGame\Config\Mobile\MobileGame.ini
    MobileGame\Config\DefaultInput.ini -> UDKGame\Config\Mobile\MobileInput.ini
    For packages referencing MobileGame, those references should be fixed up automatically so existing maps should “just work”. Maps with the mobile game extension will still work but its recommended that the extension be changed to .udk for consistency. New maps or maps saved using save as, will always be saved with .udk unless explicitly set.”

    Also:

    “The MobileGame, MobilePC, and MobilePawn classes have been renamed to SimpleGame, SimplePC, and SimplePawn, respectively.”

    • Rachel says:

      Oh jeesh yeah, I wrote these tutorials awhile ago. For some reason I was thinking of the September 2011 build, but that was the book.

  6. Don says:

    Hi Rachel,
    Having the same trouble as Tyler,

    No problem with setting up the folder structure and .uc files in the Src folder but getting the code to compile by editing the “UDKGame\Config\DefaultEngine.ini” throws up the error:
    Superclass MobileGame of class AwesomeMobileGame not found, same with Pawn and PC

    Wondering if there is something in the uc files that needs to be modified or if there is another ini file somewhere that needs to be updated.

    Keen to work on an orbit Cam for iOS once I get this stage sorted.

    Any advice or directoin (from anyone) would be greatly appreciated.

    • Rachel says:

      Hmm, it sounds like my tutorial is out of date. I don’t think MobileGame exists anymore, I think it’s SimpleGame now. I’m out of town so I can’t check the code at the moment, but let me know if that works! Also, disregard the orbit cam tutorial for now, it’s extremely ugly and I need to completely trash and rewrite it.