Legacy:Default Properties

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

This is a special part of the UnrealScript Class syntax. It's a block of script at the end of a class that declares default values for class properties. This block cannot contain any executable code, and uses its own special syntax that is different from ordinary UnrealScript code. Generally, this is similar to the syntax for T3D files.

Default properties are inherited by subclasses, and may in fact be overridden several times as you go down the class tree. The most "recent" (lowest subclass that has a setting for it in its default properties) takes precedence in this case. This also goes for parts of a struct or array, e.g. you can change the red value of a color property and the green, blue and alpha values are inherited from the superclass.

Syntax

This shows how to set defaults for arrays (both static and dynamic ones), floats, ints, booleans, strings, structs (MyColor), enums, objects (MyProjectileClass; sounds, textures, fonts, meshes or subobjects are handled likewise) and names. Note that you can also specify objects only by giving the name, i.e. RocketMk2 instead of class'Botpack.RocketMk2'.

<uscript> defaultproperties {

    MyFloat=8.000000
    MyInt=5
    MyBoolean=True
    MyString="Hello World!"
    MyEnum=ENUM_Something
    MyName=CliffyB
    MyProjectileClass=class'Botpack.RocketMk2'
    MyColor=(R=128,G=20,B=255)
    MyStaticArray1(0)=5
    MyStaticArray1(2)=3
    MyDynArray1=("array","on","a","single","line")
    MyDynArray2(0)="multiple"
    MyDynArray2(1)="lines"
    MyDynArray2(2)="for"
    MyDynArray2(3)="this"
    MyDynArray2(4)="one"

} </uscript>

Notes

  • The syntax of the default properties block is pretty strict for an arcane reason. Particularly adding spaces before or after the "=" will lead to errors in pre-UT2003 versions. Trailing semicolons are not needed (pre-UT2003 they will cause an error; post-UT2003 you can put them in if you like). Also adding spaces inside the parentheses for a struct or single-line dynamic array will not work. If a struct has a Name variable, double quotes should be used instead of singles.
  • As stated above, the default properties block is only parsed, but in no way executed. You can't put any executable code in there (or complex expressions or variable references at the right side of an assignment, for that matter). You can not use constants to initialize a value in defaultproperties. The compiler will not always give you an error; sometimes it will simply replace the constant with the appropriate zero value.
  • Don't expect block comments to work properly there either, you can comment out the whole block but trying to comment out a line can produce weirdness. Block comments do work in UT2004. The following example will not count as a comment, but will be parsed as if the /* */ wasn't there: <uscript>

/* defaultproperties {

    MyVar=3

}*/ </uscript>

Guest: Well does it work or doesn't it? The above says one thing, then the opposite, then it's contradicted again below!

Guest2: I guess that block comments DON'T work but single-line comments DO.

  • While block comments do not work (the default properties parser will miss the start and end due to the nature of the parser), it does in fact respect single-line comments.

<uscript> defaultproperties {

   // This is a valid comment
   //MyVal=0.1234

} </uscript>

  • When assigning values to static or dynamic array elements in the defaults block don't use square brackets, it won't work, use ordinary parentheses or you'll get an "unknown property in default block" error when compiling.
  • The default properties block will not show up when you are using UnrealEd's build-in Script Editor. You can however right-click the class in the actor browser and select "Default Properties" to check and modify them.
  • Any variables that specified as config will have any default values replaced by those specified in the appropriate .ini file, just as placed Actors with modified values will replace those specified in the class.
  • Note that newer builds of the engine (i.e. anything newer than UT) support more robust parsing of the defaultproperties, including extra whitespace and semicolons at the end of lines.
  • The compiler that came with UT2003 checks whether classes specified in the defaults block exist, but it doesn't check whether they are allowed there. In particular this means you can assign class'Commandlet' to a variable of type class<Actor>. The variable will contain the default value None then, but the compiler doesn't complain about it.

Inheritance

Not readily apparent to some is that your defaultproperties block can become fairly large if you consider how much you've inherited. Consider

Object >> Actor >> Inventory >> Weapon >> CustomWeapon

I've seen a few people who assume that defaultproperties is something special, but it's just a basic constructor for your class so all the variables and settings from every class in your tree are available there as well. In the case of Weapon bJustTeleported (Actor) and bMovable (Actor) are available for your use, even if they don't make much sense by the time you get to them.

Accessing

<uscript> SomeActor.default.<property>=<DefaultValue>; // if you have an actor of the class class'SomeClass'.default.<property>=<DefaultValue>; // if you don't </uscript>

It's probably obvious, but if you set the default for a class in your script, it won't affect the property of objects of the class, even if those have not changed from default: those were set from the defaults when the object was created.

Features in later engine versions

It is possible to create subobjects in the defaultproperties block of a class. This technique is widely used in the UT2003 XInterface package to create GUI controls to be placed on a dialog box.

Default properties in UnrealEd

The Default properties block is omitted in UnrealEd's script editor. Instead, properties are set in an extra instance of Actor properties window, accessed from the Actor classes browser. Do one of the following:

  • Select the class, Actor Classes Browser Menu -> Class -> Default Properties...
  • Select the class, and click the properties button on the Actor classes browser toolbar
  • Right-click the class and select Default Properties... from the context menu.

The downsides of this behavior are:

  • If you paste in a script, you'll have to remove the Default properties block: it won't compile.
  • You can't access hidden variables in the default properties window.

To access hidden variables, call up the window with the console command:

editdefault class=<classname>

Comments

zStorm: (Fixed) It seems as though UCC under certain circumstances has issues with decompiling the default properties. If for instance you decompile a file that has a struct in the default properties, it may insert spaces into the struct declaration.

What should be ZoneGravity=(X=0.00,Y=0.00,Z=-950.00) becomes ZoneGravity=(X=0.00, Y=0.00, Z=-950.00) which is not allowed.

JamesKilton: Just something I noticed: Arrays in Default Properties are usually accessed through (). However, take this example:

<uscript> struct myStruct {

 var int intArray[3];

};

var myStruct someVar;

defaultproperties {

 // Compile fails:
 someVar=(intArray(0)=1,intArray(1)=1,intArray(2)=1)
 // Compile passes:
 someVar=(intArray[0]=1,intArray[1]=1,intArray[2]=1)

} </uscript>

Really weird double-standard here, just something to watch out for.

BigJohn: I've done some funky struct in an array stuff for one of my actors, and here's how it goes:

<uscript> struct Attack { var name AnimName; var string HowTo; var int length; };

var attack spclAttacks[10];

defaultproperties { spclAttacks(0)=(animName="AltAttack",HowTo="dr1",Length=3) } </uscript>

biggest issue I had was to make sure that nowhere in the property is there a space. (thanks pospi)

Related Topics