Once I get that upgrade to 36-hour days, I will tackle that. – Mychaeel

Legacy:Class Syntax

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

A class is a piece of UnrealScript that can be thought of as a small program. See Wikipedia:class (computer science) and Object Oriented Programming Overview for the basics of this concept. The rest of this page covers the UnrealScript syntax for declaring classes.

Declaration[edit]

Class definition syntax:

class MyClass extends ParentClass <modifiers>;

expands vs. extends[edit]

UnrealScript originally used the keyword expands in the class declaration, but long ago switched to extends, the keyword used in Java. The UT-generation compiler supports both and treats them the same (although expands was considered deprecated for a while already), but in newer engine generations expands won't work. So, always use extends when you have a choice.

Optional modifiers[edit]

...that affect only this class[edit]

abstract 
This class cannot be spawned, it's a base class only. Usually the useful functionality is implemented in subclasses. Examples: Keypoint, Triggers, Pawn.
config or config(name
This class supports saving its config properties to a configuration file. By default this is the Game Ini File (the configuration file that has the same name as the executable file of the game, e.g. UnrealTournament.ini or UT2003.ini). Using config(name) overrides the default config file name for this class. There are two special names that can be used here: System uses the game ini file, User uses the User.ini. Both names can be mapped to other files via the game's -ini=...- and -userini=...- command line parameters.
NoUserCreate 
Only in UT or earlier engine versions. This class cannot be placed in a map using UnrealEd. In newer versions, use notplaceable.
Native 
Some behaviour of this class is handled by native code. See Native Coding.
(No)NativeReplication 
Replication of variables and functions declared in this class is completely handled by native code.
SafeReplace 
From a now disappeared page about undocumented UnrealScript features: Specifies that a reference to this class may safely be set to Null or default if the class object can't be found in any packages. For example, you create a map that uses textures from the package "Rugs.utx". You have two floors in your map, one surface using the "Persian" texture and the other using the "Throw" texture. If you close your map, delete "Persian" from the texture package and reload your map, the surface that was referencing Persian will be changed to reference the default texture. This is because the texture class was declared SafeReplace. Note that packages are not SafeReplace. That means if you had deleted the Rugs.utx package completely (deleting the file), your map would not load because the package must be found.
Within ClassName 

Only works in Unreal Engine 2.0 and later engine version, and with classes not derived from Actor. It allows access to the holding class's members it is declared in. The holding class is optionally pointed to by the identifier 'Outer'. For this to work, the class can only extend Object.

Examples include PlayerInput, AdminBase, and CheatManager. All three of these are declared to be "within PlayerController" and extend object. Since they aren't actors, their functions and variables cannot be replicated. Also, if you look carefully, you will notice that these classes can call Outer functions (and possibly reference Outer variables) without making an explicit reference to "Outer". This has an effect that is somewhat like multiple inheritance, because it can call Outer and Super functions.


PerObjectConfig 
Stores configuration information on a per-object basis rather than a per-class basis. This means that each object should have a separate configuration section in the configuration file based on its name.
Transient 
This class is not included when saving a game state.
NoExport 
Don't export to C++ header. "ucc make -h" won't automatically generate a C++ header for native functions/events. Please see the following pages for more information:
* Native Functions
* UnrealScript Q&A (May 2000)
dependsOn(ClassName

Only works in Unreal Engine 2.0 and later and takes a class name as parameter. Tells the compiler to process another class of the same package first because this class depends on an enum or struct declared in that other class. If your class depends on more classes you have to use the modifier several times, like in xPawn:

class xPawn extends UnrealPawn
    config(User)
    dependsOn(xUtil)
    dependsOn(xPawnSoundGroup)
    dependsOn(xPawnGibGroup);

Note: The compiler does not check dependson for accuracy and will cause a GPF if you misspell a class name or if you include spaces inside the brackets, like this:

class AClass extends Object
    dependsOn( SomeOtherClass );

To access the structs in a class that is depended on in this way, you must prefix it with the class name, like so:

class A extends B dependson(ThirdClass);
 
var ThirdClass.SomeStruct Somevariablename.

In certain cases the DependsOn() modifier might not be neccessary. Note that you cannot use it to resolve circular dependencies between classes in the same package.


exportstructs 
Export all structs declared in this class to C++ header. This is equivalent to declaring all structs in the class as "native export"
CacheExempt 
UT2004 only. Only used in cache metaclasses, such as GameInfo, Mutator, Weapon, Vehicle; ignored for any non-cached class. This class modifier is used to indicate that the values of this class's cacheable properties should not be exported to the .ucl file. In general, mod authors will probably never need to use this specifier, as it used for gametypes, weapons, mutators, etc., which should not appear in GUI/webadmin lists.
HideDropDown
UT2004 only. This class will not appear in drop down listboxes in UnrealEd.
ParseConfig
UT2004 only. The .ini file for this class may be specified on the command-line, using the syntax ' -classname=filename.ini'. If no parameter is specified on the commandline, the class uses its default configuration file (the system ini, unless a different ini is specified in the class declaration using Config(xx)). For example, in order to specify a unique .ini file for the usernames & passwords used by the advanced administration system (xAdmin.xAdminConfigIni), add the parameter ' -xAdminConfigIni=filename.ini' to the startup commandline. If the commandline doesn't contain this parameter, username/password information will be stored in the xAdmin.ini file, because this is what the xAdminConfigIni class declares as its config file.

...that also affect subclasses[edit]

(dont)collapsecategories 
Only works in Unreal Engine 2.0 and later. Collapses all property groups into one main property group.
hidecategories(group list
Only works in Unreal Engine 2.0 and later. Takes a comma-seperated list of variable groups. These groups will not be shown in UnrealEd's property windows, e.g. the Actor Properties or Texture Properties. (also see Displaying Variables In UnrealEd)
showcategories(group list
Only works in Unreal Engine 2.0 and later. Opposite of hidecategories. Variable groups that have been hidden in a superclass can be made visible again with this modifier.
(not)placeable 
Only works in Unreal Engine 2.0 and later. The class must also be derived from actor or a subclass of actor. This means you can(not) place Actors of this class in a level.
(not)editinlinenew 
Only works in Unreal Engine 2.0 and later. Classes also cannot be a subclass of actor. See Editinline.
instanced 
See Automated Component.
From what I can gather this signifies that the member variable is owned by the class rather than just being a reference. It will replace what would normally be a 4-byte reference with an n-byte instance where n = sizeof(YourClass). The benefit is that it allows Object members to be visable and editable in the Unreal editor without having to derive from Component.
WARNING: when refactoring and changing to instanced old maps will crash when trying to load. To fix, delete appropriate world objects from map before refactoring and re-place them after building scripts.

Working with classes[edit]

To cover:

Casting[edit]

rough snip from one of tarquin's unl33t forum postings:

Example of casting: the syntax

MyGame(Level.Game).Leader

Level.Game is a variable that's been declared to point to an object of class GameInfo.

You can make it point to a subclass, that's the whole point of OO (polymorphism, isn't it?)

GameInfo class doesn't have a Leader property, so to access that property, you've got to temporarily specialize that variable.

See Typecasting.

Related Topics[edit]

Discussion[edit]

DaWrecka: Something I've been trying to find out lately is; Is it possible to find out whether an object or actor is abstract, based on the class reference? I'm trying to code a new monster manager for Fraghouse Extension, and I'd like to weed out the abstract classes from the monster list if possible. So far the only plan I've got is trying to spawn the monster, and testing whether it succeeded - a definite Plan Z due to the fact this would be from a GUI. Spawning would work, but the lack of a GameInfo would likely lead to multiple Accessed Nones.

Wormbo: There's no way to tell directly. Try spawning it in the entry level, that should have a GameInfo.