Navigation
API > API/Runtime > API/Runtime/CoreUObject
Re-instance UScriptStruct with their new version. It uses the Reference Collector (AddStructReferencedObjects) to find all InstancedStruct/PropertyBag/... that use the struct. To restore only the modified property, the UObject that owns the UScriptStruct is serialized before the compilation process starts, and then serialized back once the new UScriptStruct is compiled. It utilizes tagged serialization and the default value of the archetype to obtain the new default values and restore the previously modified values. The tagged serialization only serialized the modified properties. For proper reinitialization, the owning struct must be different from the archetype. Override Identical and return false to make sure the owning struct is serialized. For UUserDefinedStruct re-instantiation, the original UScriptStruct and the new compiled UScriptStruct are the same instance. Other UScriptStruct types use different instances.
Algo:
For UUserDefinedStruct, create a duplicate. It will be used instead of the original UScriptStruct until it is compiled.
Gather all UObjects that contain a soon-to-be-dirty UScriptStruct.
For UUserDefinedStruct, replace the UScriptStruct with the duplicate.
Serialize (save) the UObjects (to gather only the modified properties).
Compile the UScriptStruct.
Serialize (load) the same UObjects. Replace the UScriptStrut with the new compiled version.
| Name | FStructReinstancer |
| Type | class |
| Header File | /Engine/Source/Runtime/CoreUObject/Public/StructUtils/StructReinstancer.h |
| Include Path | #include "StructUtils/StructReinstancer.h" |
Syntax
class FStructReinstancer : private FNoncopyable
Inheritance Hierarchy
- FNoncopyable → FStructReinstancer
Structs
| Name | Remarks |
|---|---|
| FSavedDataForReinstantiation | |
| FStruct |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| bRequiresReinstantiation | bool | StructUtils/StructReinstancer.h | ||
| bSerializingForReinstantiation | bool | StructUtils/StructReinstancer.h | ||
| ObjectsToReinstantiate | TArray< FSavedDataForReinstantiation > | StructUtils/StructReinstancer.h | ||
| StructuresToReinstantiate | TArray< FStruct > | StructUtils/StructReinstancer.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
void AddStruct
(
TNotNull< const UScriptStruct* > Original, |
Add a UScriptStrut to the re-instancer and its duplicated struct. | StructUtils/StructReinstancer.h | |
void CollectObjects() |
Collect all objects that use structs that will be re-instantiated. | StructUtils/StructReinstancer.h | |
const UScriptStruct * GetCompiledReinstantingStruct
(
TNotNull< const UScriptStruct* > Struct |
Find the new compiled UScriptStruct created for the original struct. | StructUtils/StructReinstancer.h | |
const UScriptStruct * GetDuplicatedReinstantingStruct
(
TNotNull< const UScriptStruct* > Struct |
Find the duplicated UScriptStruct created to keep the raw memory readable while the struct is compiled. | StructUtils/StructReinstancer.h | |
bool IsReinstanting
(
TNotNull< const UScriptStruct* > Struct |
Is the struct added to the FStructReinstancer. | StructUtils/StructReinstancer.h | |
bool IsSerializingForReinstantiation() |
Serializing the UObject owners to gather the modified properties. | StructUtils/StructReinstancer.h | |
void MarkAsRequiresReinstantiation() |
The current collected UObject contains at least one UScriptStruct that is being reinstantiated. | StructUtils/StructReinstancer.h | |
void ReinstanceObjects() |
Re-instantiate previously collected objects with the new struct. | StructUtils/StructReinstancer.h | |
void SetCompiledStruct
(
TNotNull< const UScriptStruct* > Original, |
Set the new compiled UScriptStrut created for the original struct. | StructUtils/StructReinstancer.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static FStructReinstancer * GetInstance() |
StructUtils/StructReinstancer.h |