I'm a doctor, not a mechanic

Legacy:Variable Syntax

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

Variable Declaration[edit]

Class variables[edit]

The var keyword is used after the class declaration to declare class variables. Using parentheses after the keyword var makes the variable appear in the Actor properties window for objects of that class. Using group makes them appear in a certain group like Display. If group is not specified the class name is used as group. See Displaying variables in UnrealEd.

var(group) modifiers type name, name, ...;
var() modifiers type name, name, ...;
var modifiers type name, name, ...;

Default values of variables are set in the Default Properties block. For the possible values of the 'type, see Variable Type.


Constants are just names for certain values and can be changed neither from UnrealScript nor from native code. Constants can be declared anywhere in a class, even inside functions, but they are always available in the whole class.

const name = value;

Note: Constants will not be evaluated in the default properties block. You will have to use literal values there.

Local Variables[edit]

Local variables are only available in the function they were declared in.

local type name, name, ...;

Function Parameters[edit]

See Function Syntax.


Static Arrays[edit]

A static array has a length known at compile time and is not resizeable.

To create an array just specify its length in brackets behind the variable's name:

var/local type name[length], ...;

Type can be any of the built-in types (except bool) or a struct or an object. (Enums?) The length needs to be a constant integer value greater than 0, i.e. you can also use a constant instead of a number here. The array's size cannot be changed once the array has been declared. All elements are initialized to their null values. (see Built-In Types below)

Array values are accessed via name[0] to name[length - 1]. If you need to get the length of the array use ArrayCount(name).

Note: UnrealScript doesn't support multi-dimentional arrays of any kind. To fake multi-dimensional arrays you either have to use a larger array and write accessor functions for it that transform multiple indices to a the actual array index or use a declaration like this:

struct TMultiArray {
  var int Y[100];
var TMultiArray X[100];

Later, in a function you can access this fake multi-dimensional array with this syntax:

X[50].Y[50] = 31337;

Note on replication: The elements of a static array count as indvidual variables with identical replication conditions, so you can replicates arrays of any size you want as long as the individual elements obey replication restrictions.
However, as parameter of a replicated function only the first array element will arrive at the remote machine. To get around that, make the array part of a struct and use that as the function parameter.

Dynamic Arrays[edit]

A dynamic array is an array that can be lengthened or shortened to accomodate the number of elements in the array.

See Dynamic Array.

Variable Modifiers[edit]

Modifier keywords come between the var keyword and the type keyword. Any number of modifiers can be used, including zero.

 var transient int MyVar;
The value of this variable can be saved to a *.ini file and is class specific. (see Config Vars And .Ini Files)
The variable cannot be changed from UnrealScript, but only through native code.
(Only in v600+ builds of the Unreal Engine.) The compiler prints the warning "Reference to deprecated property variable name." when a variable marked as "deprecated" is used in the code.
(Only in v600+ builds of the Unreal Engine.) Can be read as 'Editor Findable.' If this property is selected in the actor properties window within UnrealEd, there will be a "find" button beside the property in question. If you click the "find" button, the cursor will change to the "finder" cursor. If an actor is clicked while the "finder" cursor is displayed, the currently selected property (in the actor properties window) will be set to the actor clicked upon. For an example, see Volume.DecorationList
The variable cannot be changed in UnrealEd, even though it might be displayed there.
Prevents users from changing a dynamic array's length in the properties window.
(Only in v600+ builds of the Unreal Engine.) Allowes UnrealEd users to edit the object referenced by this variable within the property window of the object this variable belongs to. See editinline for details.
Whether or not this property should be displayed in the default properties of classes exported with UnrealEd or the BatchExportCommandlet. Just a guess, but export probably overrides a class' noexport declaration for subobject exporting.
The value of this variable can be saved to a *.ini file and is also used for all subclasses. (see Config Vars And .Ini Files)
<wiki>"Input" variables can be mapped to the console, by binding a key to a special console command. Only byte or float variables can be input variables. The appropriate console commands to bind an input variable to a keyboard/mouse/joystick input are:
  • Button <variable name>: The input variable is 1 if the button is pressed, 0 otherwise. Should be a byte variable.
  • Count <variable name>: This variable will increment every time the button is pressed. If it is an axis, this will increment every time a new input is recieved. This can be useful for checking to see if an input has changed since it was last checked. It will wrap around when it reaches 255. This should use a byte variable.
  • Axis <variable name> <arguments> The only one that takes arguments is also the only one meant for use with floats. This captures axis movement. Depending on the axis in question, this may be an absolute value (as with joysticks) or it may be a relative value. (as with mice) Arguments are specified in the format argument name=value and the valid arguments are:
    • Speed: Appears to be a simple multiplier for the input. Seems to be useful on mice.
    • SpeedBase: Appears to be an exponential multiplier for the input. Seems to be useful on joysticks.
    • Deadzone: Inputs within this amount of zero are not set into the axis variable and are registered as 0. This appears to be applied BEFORE speed or speedbase.
    • Invert: Interestingly, this appears to be a simple multiplier. Set to -1 to invert the axis.

Note that Interactions are better for most input capturing, as input variables require subclassing PlayerController. (or PlayerPawn in the case of UnrealEngine1) Axis input variables can also only be accessed within the PlayerTick function - outside of this function they will always be zero. (though the variable can be stored in another variable that will be accessible anytime.) The only real reason to use input variables in UnrealEngine2 is because Interactions do not capture joystick axis movement.


The default value of this variable can be located in a localization file (*.int, etc.).
This variable is set by native code.
The variable is only visible from the class it was declared in, but not from any of its subclasses.
The variable is only visible from the class it was declared in and all subclasses.
This variable will not be included when saving the current game. (in Unreal)
The value of this variable does not change when traveling between levels.

Related Topics[edit]