Friday, December 18, 2009

Scripting a simple Game in UDK

Let’s call our new game SGGame – with SG standing for standing for Simple Game. Prefix your game as you please.

First create a directory in your \Development\Src\ and give it the same name i.e. SGGame. In it, create a directory called Classes.

Next, let’s create a file in the Classes directory and call it SGGame.uc. Open the file in your favorite text editor and type in the code below.

class SGGame extends UTGame

config(Game);

defaultproperties

{

}

This basically defines a class called SGGame that extends the UTGame class. Generally, your game will extend a subclass of the GameInfo class. By extending the UTGame (also a subclass of GameInfo) class we gain a lot of functionality that we would require for an FPS game.

Now let’s compile our game just to make sure everything is fine so far. To do this, we want to run the UDK executable with a special command line argument – make. To make this easier as we will be using it a lot, we will make a shortcut on the desktop for this.

Go into the \Binaries\Win32 directory and copy the UDK.exe file. Right click on your desktop and click on Paste Shortcut. Rename the shortcut to Compile UDK Scripts. Right click on the shortcut and go to its properties. In the target section, add make.

Mine looks like this - X:\UDK-2009-12\Binaries\Win32\UDK.exe make

Running this right now will not compile your new game’s scripts because UDK does not yet know about our new game. To do this, we need to modify one of the .ini files. Go to \UTGame\Config and open DefaultEngine.ini in your text editor.

NOTE: By default, the file is read only; you need to make it writable from its properties to make these changes.

Scroll down to the [UnrealEd.EditorEngine] section and add the following line.

+EditPackages=SGGame

The UnrealEd.EditorEnginesection is used by the compiler to determine which packages exist and need to be compiled when they change.

The + (plus) basically tells the engine to add the line in the generated UTEngine.ini file.

NOTE: Whenever you make a change to the DefaultEngine.ini the engine will generate a new UTEngine.ini file on the next run. More information on this can be found in the Configuration File section of UDN.

Double click on the compiler shortcut to compile our game’s scripts. If there are any syntax errors in the file, you will get the warnings/errors in the compilation window. It should however compile without any problems.

It’s time to see what we’ve done so far. We will load up the examplemap map for this. We’ll use another shortcut and command line argument to run the map with our game. Copy and paste a UDK shortcut like we did before. Call this Simple Game(or whatever else your prefer). Open its properties and add ExampleMap?Game=SGGame.SGGame

This basically tells UDK to load the map called ExampleMap and run the game called SGGame in the SGGame package.

There you go; you have a basic game up and running.

The UDK bandwagon

If you are a game development enthusiast/hobbyist/indie like me, you've probably heard of UDK. If not, get out from under that rock and head staright to http://www.udk.com. It's pretty much an Indies dream come true.

I've been using it since early November and its a hell of a steep learning curve but at the end of the day, its Unreal. I've joined a small indie team as an Unreal Scripter to work on a project called Nothern Island 1983.

The feature list is very impressive, including speed tree, face fx, the unreal editor in all its glory, documentation via the UDN and recently released video tutorials. Christmas really did come early this year and the Indie(read me) has to stop making excuses.