| Home Page | Recent Changes | Preferences

Class Syntax

A little bit about classes here... and a link to the OOP Overview page too.

Class definition syntax:

class MyClass extends ParentClass <modifiers>;

"expands" vs. "extends"

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

...that affect only this class

Abstract
This class cannot be spawned, it's a base class only, eg Keypoint.
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 games -ini=... and -userini=... [command line parameter]?s.
NoUserCreate
Only in UT or earlier engine versions. This class cannot be placed in a map using UnrealEd.
Native
Some behaviour of this class is handled by native code.
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 UT2003 non-actor classes. It allows access to the holding class' 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:
dependson(ClassName)

Only works in UT2003 classes. Takes a class name as parameter. It allows you to use structs from another class that the given class is not derived from. This is important if you have to pass a struct as an argument to a function in that class. The dependson modifier takes exactly one parameter. 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.

Wormbo: Well, I didn't have problems accessing structs in other classes without dependson(). There's [this post at the Atari UT2003 Coding forum] where Ron Prestenback (Epic programmer) posted the followig:

DependsOn() may or may not be necessary depending on which class the compiler attempt to compile first. DependsOn() simply tells the compiler to compile the other class first.

This and the fact that I could use enums and structs declared in other classes and/or packages that are completely independant from my class makes me believe the description on this page is wrong.

exportstructs
Export all structs declared in this class to C++ header. This is equivalent to declaring all structs in the class as "native export"

...that also affect subclasses

(dont)collapsecategories
Only works in UT2003 classes. Collapses all property groups into one main property group.
hidecategories(group list)
Only works in UT2003 classes. 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 UT2003 classes. 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 UT2003 actor classes. This means you can(not) place Actors of this class in a level.
(not)editinlinenew
Only works in UT2003 non-actor classes. See Editinline.
instanced
See Automated Component.

Working with classes

To cover:

  • the class<foo> syntax
  • the use of myObject.IsA(class)

Casting

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

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