Learning UnrealScript Part 1 – What is UnrealScript?

UnrealScript is, put simply, a programming language developed by Epic Games specifically for use with the Unreal Engine.

But the Unreal Engine is written in C++…so why bother to make an entirely new language? One reason is that it provides a “layer of abstraction”: what is done in UnrealScript is guaranteed to only affect the game, and not the engine itself. Dig around a bit in the code you get with UDK. See those “native” keywords? Those functions are written in C++. Messing with those could seriously screw up the engine, which is why Epic won’t let you even see them. UnrealScript lets them put a wall between you and the intestines of their beast and keeps your game in perfect working order.

It’s important to understand this because UnrealScript does not compile into real machine code. Rather, it compiles into bytecode, which is interpreted by the C++ “intestines” of UDK. You can write and edit UnrealScript in any text editing program: I use WOTGreal, but you could just as well use TextEdit or Notepad. Just save it with a .uc extension, run it through UDK FrontEnd, and you’re good to go.

The next thing to understand is: UnrealScript is an Object-Oriented Programming Language. Those of you who have worked with Java or C# will already know this concept, but those who have only dabbled in BASIC or C may not.

An Object-Oriented language revolves around Classes and Objects. An Object is anything that you can visualize as being a concrete “thing”: guns, vehicles, players, lights, scoreboards, menus, sound loops, etc. A Class is a sort of blueprint for Objects. One common way to think about this relationship is using food: the Pizza Class is a recipe for making the pizza, and the Pizza Object is the actual (hopefully delicious) pizza.

An Object is defined by a Class. For example, the Assault Rifle Class holds certain information about what an “assault rifle” is: it has X ammo left, it can hold a maximum of Y ammo, etc. Even things like weapon skins may be handled by the Assault Rifle Class. However, suppose every player in a deathmatch was holding an assault rifle. Although all of the assault rifles belong to the same Class, they are completely different Objects. Player1’s Assault Rifle Object may have 13 ammo left, but Player4’s own Object may have only 2 ammo left — therefore, they are NOT one and the same.

The genius thing about languages like UnrealScript is that they allow subclassing. Suppose you had a regular Assault Rifle Class:

class AssaultRifle extends UTWeapon;

How would you make an even better assault rifle? In a language like C, you would have to copy-paste all the code from the AssaultRifle into a new document, OR import the AssaultRifle for reference. Either way, good luck trying to get this relationship to work. But in UnrealScript, you can just do this:

class UberAwesomeAssaultRifle extends AssaultRifle;

Suddenly, you’ve got a child (UberAwesomeAssaultRifle) class that has inherited ALL the code from its parent (AssaultRifle) class, and you’re free to modify it however you see fit. So, you could take the PlayFireEffects() function from the AssaultRifle Class:

function PlayFireEffects() {
 //BLOOD, etc.

and make it even better:

function PlayFireEffects() {

The “super” simply tells UDK to run the code from the parent class, so that all the functionality from AssaultRifle is not lost. Yea, yea, I know what you’re saying…”So when do we get to actually coding something?” But, just like in learning a new language, you can’t have a conversation until you understand what you’re talking about. Next up: the UDK directory, working with Frontend, and how packages are set up.

Previous: Introduction
Next: The UDK Directory


6 thoughts on “Learning UnrealScript Part 1 – What is UnrealScript?

  1. Pingback: Learning UnrealScript – Introduction | WillyG Productions

  2. Pingback: Learning UnrealScript Part 2 – The UDK Directory | WillyG Productions

  3. I started learning UnrealScript for a couple of days , and as much as I watched videos I got more confused with it … your documentations really helps to understand what everything really means in the code , tnx , and the Irony used in text sometimes , makes reading not to be so boring for lazy guys like me . tnx very much .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s