Search public documentation:
This is a technical document describing the UnrealScript language. It's not a tutorial, nor does it provide detailed examples of useful UnrealScript code. For examples of UnrealScript the reader is referred to the source code of the engine, which provides tens of thousands of lines of working UnrealScript code which solves many problems such as AI, movement, inventory, and triggers. A good way to get started is by looking at the "Actor", "Object", "Controller", "Pawn", and "Weapon" scripts. This document assumes that the reader has a working knowledge of C/C++ or Java, is familiar with object-oriented programming, has played Unreal and has used the UnrealEd editing environment. For further reading, UnrealWiki also provides a great deal of information over the UnrealScript language in their UnrealScript Overview. For programmers who are new to OOP, it is highly recommended that you go to Amazon or a bookstore and buy an introductory book on Java programming. Java is very similar to UnrealScript, and is an excellent language to learn about due to its clean and simple approach.
UnrealScript was created to provide the development team and the third-party Unreal developers with a powerful, built-in programming language that maps naturally onto the needs and nuances of game programming. The major design goals of UnrealScript are:
- To support the major concepts of time, state, properties, and networking which traditional programming languages don't address. This greatly simplifies UnrealScript code. The major complication in C/C++ based AI and game logic programming lies in dealing with events that take a certain amount of game time to complete, and with events which are dependent on aspects of the object's state. In C/C++, this results in spaghetti-code that is hard to write, comprehend, maintain, and debug. UnrealScript includes native support for time, state, and network replication which greatly simplify game programming.
- To provide Java-style programming simplicity, object-orientation, and compile-time error checking. Much as Java brings a clean programming platform to Web programmers, UnrealScript provides an equally clean, simple, and robust programming language to 3D gaming. The major programming concepts which UnrealScript derives from Java are:
- a pointerless environment with automatic garbage collection;
- a simple single-inheritance class graph;
- strong compile-time type checking;
- a safe client-side execution "sandbox";
- and the familiar look and feel of C/C++/Java code.
- To enable rich, high level programming in terms of game objects and interactions rather than bits and pixels. Where design tradeoffs had to be made in UnrealScript, I sacrificed execution speed for development simplicity and power. After all, the low-level, performance-critical code in Unreal is written in C/C++ where the performance gain outweighs the added complexity. UnrealScript operates at a level above that, at the object and interaction level, rather than the bits and pixels level.
- UnrealScript Classes
- UnrealScript Variables
- UnrealScript Default Properties
- UnrealScript Metadata
- UnrealScript Functions
- UnrealScript Expressions & Operators
- UnrealScript Control Structures
- UnrealScript Iterators
- UnrealScript States
- UnrealScript Preprocessor
- UnrealScript Interfaces
- UnrealScript Delegates
- UnrealScript Replication
- Dynamic Arrays - Dynamic arrays now have a new function find() to find the index of an element
- Dynamic Array Iterators - The foreach operator now functions on dynamic arrays.
- Accessing constants from other classes:
- Tooltip Support - Editor property windows now display tooltips when you mouse over a property, if that property has a comment of the form
/** tooltip text */above its declaration in UnrealScript.
- Default properties - processing of the defaultproperties block has been changed\improved a bit
- Struct defaults - structs can now also have default properties
- It is no longer allowed to set default values for config or localized variables
- Defaultproperties are readonly at runtime, it is no longer allowed to do
class'MyClass'.default.variable = 1
- Metadata Support - Extend in-game and in-editor functionality by associating properties with various types of metadata.
- Debugging Functions - new debugging related functions have been added
- Multiple timer support
- Default function argument values - the default value for optional function arguments can now be specified.
- Stacking states - you are now able to push and pop states onto a stack
- UnrealScript Preprocessor - support for macros and conditional compilation
- Interfaces - Support for interfaces has been added
- Delegate function arguments - UE3 now allows delegates to be passed as function arguments
- Replication - replication statements have changed in UE3:
- The replication block is only used for variables now
- Function replication is now defined by means of function specifiers ( Server, Client, Reliable )
Gameplay Profiler can help with understanding what areas of script execution are taking the most time. Debugging Tools page for more information.
Compile Process to Execution to Byte Code representaiton - see the UnrealScript Implementation page.
- The .uc script files in a package may be recompiled without breaking binary compatibility.
- Adding new classes to a package.
- Adding new functions to a class.
- Adding new states to a class.
- Adding new variables to a class.
- Removing private variables from a class.
- Adding new members to a struct.
- Removing a class from a package.
- Changing the type of any variable, function parameter, or return value.
- Changing the number of parameters in a function.
defaultpropertiesblock in the .uc file. Persistent actor state. It is important to note that in Unreal, because the user can save the game at any time, the state of all actors, including their script execution state, can be saved only at times when all actors are at their lowest possible UnrealScript stack level. This persistence requirement is the reason behind the limitation that latent functions may only be called from state code: state code executes at the lowest possible stack level, and thus can be serialized easily. Function code may exist at any stack level, and could have (for example) C++ native functions below it on the stack, which is clearly not a situation which one could save on disk and later restore. Unrealfiles are Unreal's native binary file format. Unrealfiles contain an index, serialized dump of the objects in a particular Unreal package. Unrealfiles are similar to DLL's, in that they can contain references to other objects stored in other Unrealfiles. This approach makes it possible to distribute Unreal content in predefined "packages" on the Internet, in order to reduce download time (by never downloading a particular package more than once). Why UnrealScript does not support static variables. While C++ supports static (per class-process) variables for good reasons true to the language's low-level roots, and Java support static variables for reasons that appear to be not well thought out, such variables do not have a place in UnrealScript because of ambiguities over their scope with respect to serialization, derivation, and multiple levels: should static variables have "global" semantics, meaning that all static variables in all active Unreal levels have the same value? Should they be per package? Should they be per level? If so, how are they serialized -- with the class in its .u file, or with the level in its .unr file? Are they unique per base class, or do derived versions of classes have their own values of static variables? In UnrealScript, we sidestep the problem by not defining static variables as a language feature, and leaving it up to programmers to manage static-like and global-like variables by creating classes to contain them and exposing them in actual objects. If you want to have variables that are accessible per-level, you can create a new class to contain those variables and assure they are serialized with the level. This way, there is no ambiguity. For examples of classes that serve this kind of purpose, see LevelInfo and GameInfo.