| 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. You can however, access the original subobject by using default.Controls[0] (in the above example).

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

Exporting

In UT2003 inline objects are always lost when sources are exported from UnrealEd or via the BatchExportCommandlet. In UT2004 they will be exported unless the property they are assigned to or the subobject class itself is declared as noexport.

Spawning

If you have an actor class with a subobject, and you spawn an actor of that class... does that create a new instance of the subobject too?

  • in GUI classes, yes
  • in Actor classes, we're not sure :( Seems sometimes not, but Emitters seem to do it.
  • Yes, if you are spawning a subclass of an instanced class, other wise the last actor to spawn gets control of all the other actors of the same tree's sub objects...

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In