UnrealScript Game Programming Cookbook

By Dave Voyles
  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Development Environments

About this book

Designed for high-level game programming, UnrealScript is used in tandem with the Unreal Engine to provide a scripting language that is ideal for creating your very own unique gameplay experience. By learning how to replicate some of the advanced techniques used in today's modern games, you too can take your game to the next level and stand out from the crowd.

By providing a series of engaging and practical recipes, this "UnrealScript Game Programming Cookbook" will show you how to leverage the advanced functionality within UDK. You'll be shown how to implement a wide variety of practical features using the high-level scripting language ranging from designing your own HUD, creating your very own custom tailored weapons, to generating pathfinding solutions, and even meticulously crafting your own AI.

Learn how you can fully augment your projects with UnrealScript, with the additional inclusion of specific techniques that cover disciplines as diverse as AI scripting and HUD design. Initially starting with recipes that cover tinkering with your IDE, developing archetypes, and scripting cameras, you'll soon move on to creating advanced artificial intelligence, weapons, and vehicles alongside unique HUD and inventory systems.


Publication date:
February 2013


Chapter 1. Development Environments

In this chapter, we will be covering the following recipes:

  • Using UnCodeX

  • Dungeon Defenders to save the day

  • Unreal Script IDE

  • nFringe

  • Unreal X-Editor

  • Editing runtime values with Remote Control



Working with UnrealScript can be a daunting task at first glance, especially because it has years' worth of extensive improvements and iterations, in spite of being a language only used for this application. To make things worse, UDK does not include a development environment out of the box, so we're forced to find one that best suits our needs. Fortunately there are several out there, each of which bears many pros and cons.

In this chapter, we will look at several development environments which can handle UnrealScript, define some of the perks and pitfalls of each, and highlight the benefits of understanding the source code, through UnCodeX and the Dungeon Defenders Development Kit.

So with that, let's talk about integrated development environments.

Integrated development environments

An integrated development environment (IDE) sounds far more complicated than it is, as it simply serves as a way for a developer to talk to the machine and write code for an application. It usually consists of three components, a source code editor, build automation tools, and a debugger. The IDEs we'll cover in this chapter provide all three.


Using UnCodeX

Now that we know what IDEs are and how they work, how do we use the code provided by Epic? It's there for the taking, but we need an easy way to sift through it. That's where UnCodeX comes in. Let's take a closer look.

UnCodeX is an open source tool which provides an easy interface to browse through the code, analyzes UnrealScript, and is capable of producing a Javadoc like documentation of the source code.

Every good programmer knows their source material. That doesn't mean you need to know the engine inside out, but at least take some time to understand where your most important classes are extending from, and what's available to you. There's no sense in reinventing the wheel if someone has done it for you already, right?

Getting ready

The first thing we'll need to do is acquire a copy of it for ourselves. Let's head over to http://sourceforge.net/projects/uncodex/ and download it.

Once you have it downloaded and installed, open it up. Personally, I keep it pinned to my taskbar as it is a constant point of reference for my work that I find myself accessing day in and day out, along with my other Unreal tools.

How to do it…

On the left-hand side of the screen, you'll see the package browser . This allows us to see all of the packages currently contained within your UDK directory of choice.

This can be updated manually by clicking on the Tree menu in the top-left corner of the browser, and then clicking on Rebuild and Analyse. It may take a few moments to rebuild the package, as it is sorting through any changes you may have made since the last time you wrote any code. You can check the current status of the operation in the bottom-left corner of the program.

Adjacent to the package browser is the class tree browser . Most of the IDEs we'll be working with will include a class tree as well. The tree browser allows us to dig deeper into the code by seeing exactly how each and every class in UDK are connected to one another.

You'll notice that all classes in UDK extend from the Object class. It's the base class for everything in the game and allows for everything in the game to share some common properties and functions. Actor is perhaps the class you will be most concerned with however, as it is the base class for all gameplay objects in UDK.

It can be a bit overwhelming at first, especially when you see precisely how many classes are there. Most of what is there you will never use, but it still makes for an incredible reference. It's not what you know, but more importantly it's about knowing where to find what you're looking for.

To the right of the class tree you'll see the class browser . Double-click on one of the classes from the class tree to view its contents to the right. Other classes will be underlined and colored blue, just like when you create a URL in a web browser or word document.

Hovering the mouse cursor over any of the underlined text in the class browser will draw a pop up on the screen, which illustrates the location on your hard drive where you can find that class. This is a great way to help visualize how UDK's classes are interconnected and assist you in understanding how to best utilize them to create your own.

There's more...

UnCodeX is an essential part of any UnrealScript programmer's tool belt. It can not only help you understand what is currently running under the hood, but also help you understand the best practices for extending from its base classes to create your own.

As a rule of thumb, you don't need to know the base code inside out, but it's essential that you at least have an understanding of the work Epic has laid at your fingertips. This includes the functions such as Tick, PostBeginStart.PostBeginPlayt, and the default properties block.

There are a number of other great resources to find additional content and help for UDK and UnrealScript. These include:


Dungeon Defenders to save the day

Epic isn't the only team to offer a plethora of knowledge at your fingertips. Trendy Entertainment, the development studio behind Dungeon Defenders, was also kind enough to release much of their source code and development kit, in what is known as Dungeon Defenders Development Kit (DDDK). Similar to UnCodeX, this source code allows you to have a far greater understanding of how an entire game is pieced together.

Getting ready

The DDDK can be found by downloading and installing the Steam client at http://store.steampowered.com/about/. Once installed, click on View, which is at the top of your screen, then select Tools. The DDDK is actually a piece of DLC, and can be found here.

How to do it...

One of the largest contrasts you'll find between the Dungeon Defenders source and that of UDK is their use of cameras and the player controller, as that game utilized a third person perspective. Take a few moments to sift through the code and understand the path that Trendy Entertainment took.

It's well documented too, so even a novice should be able to sift through the code and see how things are connected. Even better, Epic's UDK forums are filled with questions from other developers asking questions about that particular set of code, in addition to code from other resources, so there are chance that many of your questions have been previously answered there. Take a look at http://forums.epicgames.com/forums/367-UDK-Programming-and-Unrealscript and see for yourself. The search bar can prove to be an invaluable tool when sifting through the forums as well, considering they are rather dense and filled with subforums from a number of Epic's properties, such as Gears of War.

Moreover, some of their programmers are extremely active in the UDK forums and often provide a bit more introspection on the code and how it is used.

How it works...

As license holders, Trendy Entertainment utilizes a custom version of the Unreal Engine, thereby allowing the developers of the DDDK to have far more control of the engine than we could without the license. This wasn't always the case however, so much of the original UDK code is still in place. With the DDDK you can either create modifications for Dungeon Defenders, or total conversions to the entire game.

See also

So why did Trendy Entertainment release their source code for free? Well, publicity could be one reason. Epic heavily promoted Dungeon Defenders at launch and lauded it as an excellent example of how to utilize the engine to create something different from what they created it to do.

Copies of the game are very affordable nowadays, sometimes running even as low as a few dollars during a Steam sale, and the original demo is still free. So I'd suggest picking up a copy and seeing how it compliments all of that code you've just sifted through. Even if you don't own the game, the source is still available as free DLC through Steam or can be found at http://www.unrealengine.com/showcase/udk/dungeon_defense/.


Unreal Script IDE

The Unreal Script IDE is a professional development framework, utilizing the Visual Studio shell. If you're a .NET developer, then you should feel right at home with this IDE. It will be our tool of choice for this book for a number of reasons, but most notably for a few of the features which aren't found in any other development environment, such as the following:

  • Debugging

  • Conditional Breakpoints

  • Go To Declaration

  • IntelliSense

  • Find All References

There are many other reasons I prefer this environment over the others, but those are just some of the highlights. IntelliSense in particular is extremely useful, as it auto completes your code as you write. Furthermore, it makes for easy disambiguation for functions, methods, and variables. Find All References is also notable, as it locates any instance of a particular variable or function within UDK, and shows you where and how it's used. This is outstanding for learning the source material.

Getting ready

Head over to http://uside.codeplex.com/ to grab a copy of this free open source tool. You won't need your own copy of Visual Studio either, as this runs in an isolated shell. Bear in mind, you must have UDK installed before installing the IDE.

How to do it…

When installing the IDE, it's important to remember to select the UDK Win32 binaries folder correctly. Additionally, the source folder must be listed as C:\UDK\UDK-Date\Development\Src\; otherwise your project will appear empty when you open the solution.


This is the default installation path. Yours may be different.

From there, your Unreal Script IDE should be populated with your current project, and update itself automatically as you make changes.

There's more…

Even better, the Unreal Script IDE allows you to continue to use extensions! Head to http://visualstudiogallery.msdn.microsoft.com/, to find the ones which work best for you. Afterwards, extract the content into the Extensions folder found at C:\Program Files (x86)\Mr O. Duzhar\Unreal Script IDE (UDKDevKit) VS 2010 Isolated Shell\.



Just like the Unreal Script IDE, nFringe is a complete IDE that also uses the Visual Studio shell. Similarly, it offers many of the features that Unreal Script IDE does, but many require a commercial license of the Unreal Engine, such as Goto Native Definition for native script functions. For this reason, I prefer to use the former tool.

Pixel Mine is the development team behind this product, which comes in both premium, indie, and commercial licenses, although it can get a bit costly, as indie licenses start at $350 a seat. A trial version is available however, so you may want to consider that before taking the step into the premium pond.

Many professional AAA studios prefer to use this IDE, so focusing your efforts here may not be a bad idea. Furthermore, nFringe includes an excellent debugger, which can prove invaluable when trying to troubleshoot critical errors in your programming.


nFringe will not work with Visual Studio 2012 right out of the box. You'll need to make some changes for it to work properly, as noted in the following site:


Getting ready

Head over to http://pixelminegames.com/nfringe/ to pick up a copy for yourself. It's one small download and a pretty straightforward installation process.

How to do it…

Just as Unreal Script IDE used a Visual Studio shell, nFringe does too, but it is based on the 2008 version. Even if you don't own Visual Studio, you're still in the clear as you can run it through the shell. For those of you who do have a copy of Visual Studio, nFringe simply installs like an extension, and allows you to create new projects from your current installation. Moreover, you can also use Visual Studio Express, which is the free version of the program.

Starting a new project is as simple as opening up Visual Studio, selecting the installed UnrealEngine3 Licensee Project template, and you have all of the features of nFringe available at your fingertips. Setting up the new project is a bit more work however, as you'll need to carefully follow these instructions to do so.

Configuring the directories is the first step in creating your own project scripts:

  1. Within your UDK install directory (that is, C:\UDK\July) browse to the Development\Src folder and create a folder of your own. In this example we'll use Tutorial.

  2. Create a Classes folder inside your Tutorial folder.


    All of your scripts will be stored in here. You cannot create more folders within your Classes folder for organizational purposes. You can however create various packages within UDK to neatly separate your classes.

  3. Now we need to notify the engine that you'll be adding a new package, or collection of scripts, and that they should be compiled each time you build the game. The configuration files stored inside of UDKGame\Config are the ones which inform the engine of this package. Browse over to that folder and open the DefaultEngine.ini file.

  4. Once inside, scroll down to [UnrealEd.EditorEngine] and add the name of our own game package. It should now read +EditPackages=Tutorial.


    The order in which the packages are loaded into UDK are directly related to the order in which they appear in this .ini file. If your package relies on any of the UTGame or UTGameContent scripts (and if you extend from anything within UDK, then your package certainly does), then your package must be loaded after those scripts.

How it works…

That's all there is to it. Another reason I prefer Unreal Script IDE and even the forthcoming Unreal X-Editor is because all of this work is done for you during the initial installation, because you pointed the install towards your UDK directory.

There's more…

Extensions also work with nFringe, so most of the ones you already have installed should seamlessly integrate with your new UDK project.


Unreal X-Editor

A strong contender for the most intuitive IDE is the Unreal X-Editor. While the editor has come a long way since its initial release, it's still in its infancy, as the tool is less than one year old at the time of this writing.

Unreal X-Editor offers a number of features that makes it stand out, including the following:

  • Class Tree Viewer

  • Autocomplete

  • Code Folding

  • C# Style Commenting

  • Syntax Highlighting

  • Basic Preset Scripts

  • Run UDK Editor / UDK Game

  • Compile/Full Compile Scripts

  • Various Skins to change the Look And Feel

Getting ready

Head over to http://unrealxeditor.wordpress.com/ to download the latest version of Unreal X-Editor. Setting up the IDE is pretty straightforward as well, so no explanation is needed here.

Once you have it installed, scroll over to the Workspace Page tab, then left-click on the Settings button. A pop up should appear on screen, allowing you to customize your settings. We're looking to set your UDK installation directory, so click on that and browse to the folder where you placed UDK.

Unreal X-Editor will then have access to all of the content in that folder, including the UDK executable and any folders containing the .ini files, the UnrealScript source code, and your new folders.

That's it! This is by far the easiest tool to get up and running.

How to do it…

Unreal X-Editor offers a number of customization options, including additional skins, various font colors, and the ability to work without the GUI ribbon, thereby offering an interface more akin to our Visual Studio alternatives.

As far as simplicity goes, this IDE offers just about everything a programmer could want, and does so with a slick interface. Those of you who prefer the extra real estate and want to work without a ribbon can do that as well by doing the following:

  1. Right-click on the desktop shortcut and select Properties.

  2. In Properties, select the Shortcut tab and in the Target box add the command line -noribbon.


    An Access Denied dialog may appear, declaring that you will need to provide administrator permission to make these changes. If so, simply click on Continue, and then click on Apply and OK.

There's more...

Unreal X-Editor is perhaps the greatest IDE for those starting off with UnrealScript, and for a number of reasons. It streamlines the often intimidating and convoluted process of making changes to a game utilizing UDK.

Let's take a look at the Unreal Weapon Wizard . This tool allows us to create a weapon class with the help of visual editor. Currently only the weapon class is included, although other classes such as character and game are planned for the future as well.

All you need to do is copy and paste the names of various weapon related properties, such as mesh, muzzle flash, and pick up sound from the UDK Content Browser to the appropriate fields in the wizard and click on Next.


This is a great way to get started with learning how weapons work and are constructed in UDK. Compare and contrast your new weapon with some of those which come packaged with UDK to really get a feel of how to develop some weapons of your own without the wizard.

Afterwards, you'll be greeted with another screen for constructing your attachment class, which extends UTWeaponAttachment. This class determines how the weapon connects with your pawn when in a third person perspective.

The preceding screenshot shows the wizard for your ammunition. This is the easiest class to create, as it only requires a mesh, default starting count, and sound effect for when it is picked up. It extends UTAmmoPickupFactory, which we'll touch on more in a later tutorial.

The definitions of some of these properties can be a bit confusing, so I'll clarify these in the following list:

  • Make Splash: This displays a splash effect for the player when the projectile hits water.

  • 3P Mesh: This is the skeletal mesh for this socket. Generally left empty.

  • Muzzle Flash Socket: This determines where the flash will occur in relation to the weapon when it is fired.


    Often weapons have multiple sockets (that is, rocket launchers, double-barreled shotguns), so that's why this option is there.

The final step of the process is to create the damage class, which covers a few properties you may not be familiar with, so let's walk through some of them:

  • GibPeterbation is a Boolean, and means that when it is active the chunks will fly off in random directions

  • Bullet Hit? notifies the target that it was hit by a bullet

  • Complain Friendly Fire? determines whether teammates should complain about friendly fire with this damage type

  • Vehicle Damage Scaling determines whether or not a weapon should do more damage to be in proportion with increased health and armor of a vehicle, as opposed to just firing at a pawn

  • Damage Impulse determines the size of impulse to apply when doing radial damage

Once that's all finished, you have the option of opening all of your newly created classes to explore your creation. Take a look and see how they compare to the default weapons created in UDK and how they are assembled!

See also

There are a number of visual customizations that you can make to the editor as well, from fonts and backgrounds to panel layout. Find one that suits you best!

In addition to the visual configuration, the Unreal Frontend is available from within the Unreal X-Editor, which allows you to compile scripts, cook a level, and package a game, all from Epic's supplied interface.


Editing runtime values with Remote Control

As an UnrealScript programmer, one of your main tasks is often to assist level designers and artists by creating tools to streamline their work. While UDK comes with a robust system for adding and editing content in game, sometimes you just want to create a weapon or item to be used in game and only expose certain properties to the level creators.

We'll use a weapon as an example. Not every property is applicable to what a level designer may want or need, therefore we'll hide some of those from the designer's editor to provide a clean interface for them to work with and serve as a means to streamline their weapon creation process through the use of prefabs , which we'll touch more on later. First we'll need to understand how UDK natively allows us to do this.

UDK already provides a way for developers to alter properties at runtime through a feature called Remote Control . This allows you to make alterations to which statistics are being captured, alterations to graphics settings, as well as to scrutinize and edit actors in a scene. A plethora of console commands that allow you to edit most instantiated objects, archetypes, or actors at runtime are also at your fingertips.

When tweaking the values of a particular object within your game, for example, a pawn, the Remote Control can prove invaluable. Rather than going through the arduous process of changing code within the IDE, compiling scripts, then launching the game, you can make these small adjustments within Remote Control while the game is running. This is perfect for those moments when you want to quickly iterate and lock down the values that make a character feel just right, for example, a particular running speed, or jumping height. Once you've found the value you're looking for, you can always go back into the UnrealScript code and permanently make those changes.

Getting ready

To launch the game with Remote Control enabled, you'll need to edit your UDK launch batch file by adding -remotecontrol as an argument to the end of your UDK.exe file, just as we did for the ribbonless version of Unreal X-Editor.

Upon launching the game, it may state that your scripts are out of date and ask you to rebuild them. Just click on OK and let them compile. Once that is completed, you'll start the game as you normally do, except that there will now be another panel next to your game. This is where you'll be able to make all of your changes.

How to do it...

With Remote Control now available we can begin to create objects for level designers to work with. Let's start by creating a simple weapon:

  1. Open Unreal X-Editor.

  2. Click on the bottom half of the UDK Game icon to make the game's options editor appear.

  3. Adjust your settings so that they match the ones shown in the following screenshot. Be sure to check the checkbox marked Enable Remote Control!

  4. Click the top half of the UDK Game icon to launch the game.

  5. When your game launches, you should see the Remote Control panel appear to the left of the screen. Fire your Link Gun and then select your Actors tab.

  6. Click on the refresh icon to update Remote Control and allow it to list the latest actors into the scene.


    The Link Gun won't appear in your Actors tab, until you actually fire it and hit refresh to load everything that may have occurred since the map's initialization. That's why we're having you perform these actions.

  7. Scroll down to the UTWeap_LinkGun folder, open up the folder, and double-click on UTWeap_LinkGun_#. An in-game editor window should now appear.


    # can be any number, but is generally 0. If there are pawns that spawn into your scene, then the window may not appear immediately as that gun may be assigned to one of them. Continue to select the different UTWeap_LinkGun until the window appears for you.

  8. Scroll down to the Display tab in this new editor and take a look at the properties here. This is where you'll be able to adjust the appearance of the gun from your perspective. Feel free to play with various properties and see what they do.

  9. Checking the Hidden checkbox will hide your weapon from view.

  10. Click on the Display Scale 3D tab to bring down the X, Y, Z values for where your weapon is drawn in 3D space.


    Want to see what your weapon would look like if you were left handed?

    We know that 0 is the center of the screen, so we'll need to negate the value to move it to the left-hand side. Change the value in the Y scale to a negative number to do this.


    You'll notice that when firing our weapon, the locations where the projectiles and beam start no longer line up with our weapon. That's because we haven't changed those values.

    I also can't tell you the exact values to change, as the appearance of the weapon in the game will depend largely on the resolution with which you are running.

  11. From here you'll want to scroll down to the Weapon tab and look for Fire Offset. These values will allow you to adjust how the projectiles will appear to fire from your weapon.

There's more...

You can also call objects and actors by their names using the command line. Hitting the Tab key during gameplay and typing EditObject <nameofobject> during play will allow you to create an instance of most objects.

About the Author

  • Dave Voyles

    Dave Voyles has worked as a coordinator for the last two Indie Games Uprisings on Xbox Live, an annual event organized to highlight the talented developers and their titles on Xbox Live Indie Games. Additionally, he has released a title of his own, Piz-ong on XBLIG, as well as projects using Unity and the Unreal Engine for game jams. He's proficient in C# and UnrealScript, and all facets of the Unreal Engine, as well as a number of 3D modeling suites, including 3DS Max and Maya. He has also worked as a technical reviewer on Unreal Development Kit Game Programming with UnrealScript: Beginner's Guide, Packt Publishing and Unreal Development Kit Beginner's Guide, Packt Publishing. Moreover, he works as managing editor at Armless Octopus, a site dedicated to cover Indie game development with an emphasis on XNA and XBLIG. You can find him on Twitter under the handle @DaveVoyles or at www.About.me/DaveVoyles.

    Browse publications by this author
Book Title
Access this book, plus 7,500 other titles for FREE
Access now