NewObject
NewObject()
is the simplest UObject factory method. It takes in an optional outer object and class and creates a new instance with an automatically generated name.
template< class T >
T* NewObject
(
UObject* Outer=(UObject*)GetTransientPackage(),
UClass* Class=T::StaticClass()
)
Parameter |
Description |
---|---|
|
(Optional) A |
|
(Optional) A |
Return Value |
A pointer to the spawned instance of the specified class. |
NewNamedObject
NewNamedObject()
expands on NewObject()
by allowing a name for the new instance as well as Object Flags and a template object to be specified as an argument.
template< class TClass >
TClass* NewNamedObject
(
UObject* Outer,
FName Name,
EObjectFlags Flags = RF_NoFlags,
UObject const* Template=NULL
)
Parameter |
Description |
---|---|
|
A |
|
An |
|
(Optional) An |
|
(Optional) A |
Return Value |
A pointer to the spawned instance of the specified class. |
ConstructObject
For complete flexibility, new instances of UObjects
can be created using the ConstructObject()
function. This function calls StaticConstructObject()
, which allocates the Object, executes the ClassConstructor
, and performs any initialization such as loading config properties, loading localized properties, and instancing components.
template< class T >
T* ConstructObject
(
UClass* Class,
UObject* Outer = (UObject*)GetTransientPackage(),
FName Name=NAME_None,
EObjectFlags SetFlags=RF_NoFlags,
UObject const* Template=NULL,
bool bCopyTransientsFromClassDefaults=false,
struct FObjectInstancingGraph* InstanceGraph=NULL
)
Parameter |
Description |
---|---|
|
A |
|
(Optional) A |
|
(Optional) An |
|
(Optional) An |
|
(Optional) A |
|
(Optional) A |
|
(Optional) An |
Return Value |
A pointer to the spawned instance of the specified class. |
Object Flags
The EObjectFlags
enumeration is used to quickly and succinctly describe an Object. There are various flags to describe the type of Object, how it is handled by garbage collection, the stage the Object is at in its lifetime, etc. There are also special all or none masks and predefined groups of flags.
Flag |
Value |
Description |
---|---|---|
Object Type |
||
RF_Public |
|
The Object is visible outside of the package it is contained within. |
RF_Standalone |
|
The Object is kept around for editing even if is not referenced by anything. |
RF_Native |
|
The Objectis native. This is only used for |
RF_Transactional |
|
The Object is transactional. |
RF_ClassDefaultObject |
|
The Object is the default object for its class, i.e. the default template that new instances of that class use when being created. |
RF_ArchetypeObject |
|
The Object is a template for another object. It is treated like a class default object. |
RF_Transient |
|
The Object is not saved to disk. |
Garbage Collection |
||
RF_RootSet |
|
The Object is not garbage collected even if it is not referenced by anything. |
RF_IsLazyReferenced |
|
The Object is referenced by a lazy pointer and requires additional cleanup upon deletion. |
RF_Unreachable |
|
The Object is not reachable on the object graph. |
RF_TagGarbageTemp |
|
The Object is marked for use by various utilities that use garbage collection. This flag is not interpreted by the garbage collector itself. |
Object Lifetime |
||
RF_NeedLoad |
|
The Object needs loading. |
RF_AsyncLoading |
|
The Object is being loaded asynchronously. |
RF_NeedPostLoad |
|
The Object needs to be post-loaded. |
RF_NeedPostLoadSubobjects |
|
The Object still needs to instance sub-objects and fix up serialized component references |
RF_PendingKill |
|
The Object is pending destruction. Marks the Object as being invalid for gameplay purposes, but still a valid Object. |
RF_BeginDestroyed |
|
The Object has had |
RF_FinishDestroyed |
|
The Object has had |
Special Masks |
||
RF_AllFlags |
|
The Object has all flags. Used mainly for error checking. |
RF_NoFlags |
|
The Object has no flags. Used to avoid a cast. |
Predefined Groups |
||
RF_Load |
|
Flags loaded from Unreal files. |
RF_PropagateToSubobjects |
|
Flags inherited by sub-objects from their super-objects. |