| Home Page | Recent Changes | Preferences

Subobject

In UT2003 it is possible to define subobjects in the defaultproperties section of a class.

This technique is frequently used to set up GUI controls for dialog boxes, but it can also be used for other purposes – it's equally possible to create a ScriptedTexture object or whole Material systems.

function bool MyScaryButton_Click(GUIComponent Sender)
{
    Log("User clicked Booo!");
}

defaultproperties
{
    Begin Object Class=GUIButton Name=MyScaryButton
        Caption   = "Booo!";
        WinTop    = 0.800;
        WinLeft   = 0.100;
        WinWidth  = 0.300;
        WinHeight = 0.040;
        StyleName = "RoundButton";
        OnClick   = MyScaryButton_Click;
    End Object

    Controls[0] = GUIButton'MyScaryButton';
}

Subobjects are private to the defaultproperties section they are defined in. They cannot be referenced by their name from outside it.

In addition, subobjects act as a template for actual objects that are created when the parent object they are defined in is created. Every reference creates a new instance of a subobject; so in the following example, Controls[0] and MyVeryScaryButton would point to two distinct, different objects:

defaultproperties
{
    Begin Object Class=GUIButton Name=MyScaryButton
      // ...
    End Object

    Controls[0]       = GUIButton'MyScaryButton';
    MyVeryScaryButton = GUIButton'MyScaryButton';
}

Here is an example of a ColorModifier? object defined at compile time. It takes a single (white) icon texture and creates a red and a blue team version of it:

defaultproperties
{
    Begin Object Class=ColorModifier Name=IconPlayerRed
        Material = Texture'IconPlayer';
        Color = (R=255,G=0,B=0);
    End Object

    Begin Object Class=ColorModifier Name=IconPlayerBlue
        Material = Texture'IconPlayer';
        Color = (R=0,G=0,B=255);
    End Object

    IconMaterial[0] = Material'IconPlayerRed';
    IconMaterial[1] = Material'IconPlayerBlue';
}

Note: These subobjects are created when importing the default properties, i.e. in the compiler's last pass over all classes. This means referencing them in the default properties of other classes only works if those classes' default properties are processed after the class with the subobject. However, this order isn't guaranteed, so a project which compiles fine on one computer may not compile on a different one if a class using a different class's subobjects (e.g. a texture modifier) is suddenly parsed, compiled and imported before the class containing the subobject.

Problems

Inline objects are always lost when sources are exported from UnrealEd or via the BatchExportCommandlet.

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

Mapping Topics

Mapping Lessons

UnrealEd Interface

Questions&Answers

Scripting Topics

Scripting Lessons

Making Mods

Class Tree

Questions&Answers

Modeling Topics

Questions&Answers

Log In