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.
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.
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.
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?
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.
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.
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.
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
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:
Epic's UnrealScript forum at http://forums.epicgames.com/forums/367-Programming-and-Unrealscript
Eat 3D's UnrealScript reference at http://eat3d.com/unrealscript
Epic's UDK Gems at http://udn.epicgames.com/Three/DevelopmentKitGems.html
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.
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.
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.
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.
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/.
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:
Go To Declaration
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.
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.
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.
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:
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.
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:
Within your UDK install directory (that is,
C:\UDK\July) browse to the
Development\Srcfolder and create a folder of your own. In this example we'll use
Classesfolder inside your
All of your scripts will be stored in here. You cannot create more folders within your
Classesfolder for organizational purposes. You can however create various packages within UDK to neatly separate your classes.
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\Configare the ones which inform the engine of this package. Browse over to that folder and open the
The order in which the packages are loaded into UDK are directly related to the order in which they appear in this
.inifile. If your package relies on any of the
UTGameContentscripts (and if you extend from anything within UDK, then your package certainly does), then your package must be loaded after those scripts.
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.
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.
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.
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:
Right-click on the desktop shortcut and select Properties.
In Properties, select the Shortcut tab and in the Target box add the command line
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.
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:
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:
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!
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.
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.
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.
Open Unreal X-Editor.
Adjust your settings so that they match the ones shown in the following screenshot. Be sure to check the checkbox marked Enable Remote Control!
Click the top half of the UDK Game icon to launch the game.
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.
Click on the refresh icon to update Remote Control and allow it to list the latest actors into the scene.
#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_LinkGununtil the window appears for you.
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.
Checking the Hidden checkbox will hide your weapon from view.
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.