| Home Page | Recent Changes | Preferences

UnrealScript For Visual Basic Programmers


If you've ever programmed in Wikipedia logo Visual Basic, you already know a lot of the basic concepts of coding (no pun intended). UnrealScript is a pretty full-fledged object-oriented language though, while Visual Basic's OOP support is more or less limited to the notion of having pre-defined objects (for instance, user interface elements) with some properties and methods. You can create and use your own classes in Visual Basic (in form of "class modules"), but the average Visual Basic programmer hardly ever will feel the need to do so.

A good read for getting into the notion of Object-Oriented Programming (OOP) is OOP Overview.

Familiar Concepts


In UnrealScript, all variables need to be predeclared using either var (for class-level variables) or local (for function-level variables). Variables declared on class level are globally accessible in that class. See UnrealScript Language Reference/Variables for details.

There's no "Variant" type in UnrealScript for variables that can hold any sort of data; variables are strongly typed, and you have to typecast them in most cases if you want to assign the value of a variable of one type to a variable of a different type.

Structured Programming

UnrealScript provides very similar means for structured programming (conditionals, loops) as Visual Basic. The following table lists corresponding idioms; see UnrealScript Language Reference/Program Structure for details of their syntax.

Statements in UnrealScript always end with a semicolon (;), not (like in Visual Basic) with an end-of-line. You can therefore continue a statement in the next physical line just by not ending it with a semicolon; there's no need of an explicit line-continuation character like Visual Basic's underscore (_).

User-defined Data Types

Type Name
  Var1 As DataType1
  Var2 As DataType1
  Var3 As DataType2
End Type
struct Name {
  var DataType1 Var1;
  var DataType1 Var2;
  var DataType2 Var3;
struct Name {
  var DataType1 Var1, Var2;

  var DataType2 Var3;


Rem Comment
' Comment
/* Multi-Line Comment */
// Comment


If condition Then
ElseIf condition Then
End If
if (condition) {
} else if (condition) {
} else {
Select Case expression
  Case value1

  Case value2, value3

  Case Else
End Select
switch (expression) {
  case value1:
  case value2:
  case value3:


For var = start To end
for (var = start; var <= end; var++) {
For var = 1 To number_of_times
for (var = 0; var < number_of_times; var++) {
For var = start To end Step step
for (var = start; var <= end; var += step) {
  If condition Then Exit Do
for (;;) {
  if (condition) break;
Do While condition
while (condition) {
Loop Until condition
do {
} until (condition);

You can make your UScript more readable with the continue keyword. With it, it makes easier (thus, a good practice) to go to the next loop item if a certain condition is not met.

Subs and Functions

Sub subname (param1 As Integer, param2 As String)
  If condition Then Exit Sub
End Sub
function subname (int param1, string param2) {
  if (condition) return;
Function funcname (...) As Double
  If condition Then funcname = value : Exit Function
  funcname = value
End Function
function float funcname (...) {
  if (condition) return value;
  return value;


Arrays in UScript are easy, there is just 1 major thing to remember. Arrays start at 0! always. No wierd:

Dim SomeArray(2042 to 35930) AS Integer

just a simple:

var int SomeArray[420];

There are also Dynamic Arrays (they also ALWAYS start at 0).

Event-Driven Architecture

Everything in UnrealScript is driven by engine events, very similar to Visual Basic. The Actor class declares a variety of events that are inherited by Actor subclasses and called by the engine for every object of those classes. Sometimes you can even control how and when events are called; the Timer event, for instance, is controlled by the SetTimer function.

To have objects of your class do something, implement some or all of its events. You can, of course, also call functions from code executed for other objects, including objects of different classes. The functions of the Mutator class, for example, are actually called by other UnrealScript code.

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands


Mapping Topics

Mapping Lessons

UnrealEd Interface


Scripting Topics

Scripting Lessons

Making Mods

Class Tree


Modeling Topics


Log In