Friday, November 25, 2011

Exploring the UnrealScript source code with UnCodeX

The largest and most updated reference about UnrealScript is the source code that comes with the UDK. But sometimes it's difficult to follow the source code and understand the relationship between the classes.

To help in this task we will use a tool called UnCodeX, which was developed by Michiel 'elmuerte' Hendriks, and can be downloaded on the project page.

The installation is simple, in the first execution of the UnCodeX a message box will appear asking you to change the settings. Choose "Yes". If you want to change the settings later, access the menu: "Tree -> Settings...".

In the setting "Source Paths" add the folder "\Development\Src" of the UDK, as in the image below.


The UnCodeX will analyze all the packages and classes to display them as follows:


As an example we will research and analyze a class. In the previous tutorial I used the static mesh of "Jump Boots" of the Unreal Tournament. Let's try to find the class that implements the "Jump Boots". 

Access the Menu: "Find -> Find Class ...", type in the search query "boots" and check the "Search from the top" as in the image, so that the research is done from the base Object class.


Press "OK" to start the search. The UnCodex found the class "UTJumpBoots" which is exactly what we wanted. If we want to continue the search, press F3 to "Find Next".


Right-clicking in the class, we can see that it's in the package "UTGameContent". Let's choose the option "Show Properties..." to have an overview of variables and functions of this class.


Looking at the source code of this class we can see some functions that deal with the multiplayer aspect of Unreal Tournament.

Let's start by looking at the "defaultproperties" block. It defined the StaticMesh that will represents this class in the game. Some values are assigned for the variables, such as the variable "Charges" which indicates how many times the boots can be used.


The AdjustPawn() function adds or removes the bonus of the boots on the player. In this function we can see an comments error caused by a Copy/Paste operation.


Another interesting function is BotDesireability() that calculates the interest of the bot for this item. Basically, the function checks if the bot already has one and how many times can still be used.


The main goal of this tutorial is to show that you can learn many things about UnrealScript viewing the source code that comes with UDK.