Dynamic arrays

From Unreal Wiki, The Unreal Engine Documentation Site
Revision as of 12:51, 19 December 2008 by Wormbo (talk | contribs) (first pass)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Dynamic arrays are a special composite type in UnrealScript that contains a variable number of elements in a well-defined order. These elements all have the same type, called the "inner type" of the array.

UnrealScript's dynamic arrays are a true dynamic array implementation, i.e. unlike Java's dynamically-allocated fixed-size arrays they can be resized at runtime. The type declaration syntax was available (almost) from the start, but Unreal Engine 1 never provided any way to actually access or modify them at the UnrealScript level. In other words, dynamic arrays are fully usable in UnrealScript only in Unreal Engine 2 and later.

Unlike any other data type in UnrealScript, dynamic arrays have absolutely no support for replication. Attempting to replicate a dynamic array variable will have no effect on the remote instance of that variable. Attempting to use a dynamic array as parameter of a replicated function will result in the parameter being empty when the function is executed on the remote side.

Declaration syntax

Dynamic arrays are declared as part of the type:

array< type >

The inner type of a dynamic array can be a class limiter or the name of any other non-array type, including delegate types. Note that Unreal Engine 2 does not support dynamic arrays of type bool and the compiler will complain accordingly. Dynamic arrays of bool values are possible in Unreal Engine 3, though.

A dynamic array type can be used in all places that allow a type definition. The following example code defines a class-global dynamic array of bytes and a function that uses dynamic arrays as return type and as the type of a parameter and a local variable: <uscript> var array<byte> ByteArray;

function array<int> RoundAll(array<float> Values) {

 local array<int> Result;
 //...
 return Result;

} </uscript> The only exception are type declarations of variables, struct members and function parameters that are declared as static arrays. In this case, the dynamic array declaration is ignored.

Usage in code


Usage in defaultproperties block


Usage in UnrealEd

Buttons for modifying dynamic array properties in UnrealEd 3.
Buttons for modifying dynamic array properties in UnrealEd 3.
Buttons for modifying dynamic array properties in UT3 UnrealEd.
Buttons for modifying dynamic array properties in UT3 UnrealEd.