Mostly Harmless

Within clause

From Unreal Wiki, The Unreal Engine Documentation Site
Revision as of 11:40, 14 December 2008 by Wormbo (Talk | contribs) (New page: The '''within''' clause is an optional part of class declarations that defines the class to be an wp:inner class. It was introduced in Unreal Engine 2 and forces instances of ...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The within clause is an optional part of class declarations that defines the class to be an inner class. It was introduced in Unreal Engine 2 and forces instances of a class to be created within instances of another class.

Inner classes declared with a within clause can access members of the specified outer class without having to qualify the access with the Outer property declared in Object(U2, U2XMP, UE2Runtime, UT2003, UT2004, UDK, UT3). If a member of the inner class hides a member of the specified outer class, the access can be qualified with the Outer property without having to typecast it as the Outer property is guaranteed to reference an instance of the outer class or one of its subclasses.

Syntax

To declare a class (which extends another class) to be an inner class of a third class, use the following class declaration:

class ClassName extends ParentClass within OuterClass;

Any optional class modifiers can be added after the within class name as usual.

The following rules apply:

  • The parent class must not be the class Actor(U2, U2XMP, UE2Runtime, UT2003, UT2004, UDK, UT3) or any of its subclasses.
  • The parent class may be declared within another class. In that case, the outer class must be a subclass of the parent's outer class. This basically reduces the allowed range of outer classes without causing any inconsistencies.
  • The within clause may be omitted, actually only few classes use it. In this case the parent's outer class is inherited. (The implicit outer class of the Object class is Object.)
  • The parent class and the outer class may be the same class.

Example usage

Some examples of inner classes are CheatManager(U2, U2XMP, UE2Runtime, UT2003, UT2004, UDK, UT3) and PlayerInput(U2, U2XMP, UE2Runtime, UT2003, UT2004, UDK, UT3), both declared within PlayerController(U2, U2XMP, UE2Runtime, UT2003, UT2004, UDK, UT3). An example of "narrowing" the valid range of outer classes is GamePlayerInput - it reduces the valid outer classes from all PlayerControllers to only instances of GamePlayerController and its subclasses.