Navigation
Unreal Engine C++ API Reference > Plugins > NetcodeUnitTest
References
Module | NetcodeUnitTest |
Header | /Engine/Plugins/NetcodeUnitTest/NetcodeUnitTest/Source/NetcodeUnitTest/Public/NUTUtilReflection.h |
Include | #include "NUTUtilReflection.h" |
Syntax
enum EVMRefWarning
{
Warn,
NoWarn,
}
Values
Name | Description |
---|---|
Warn | |
NoWarn |
Remarks
FVMReflection - Reflection Helper
Description: The purpose of the reflection helper, is to allow complete access to the UE UScript/Blueprint Virtual Machine through reflection, i.e. without directly/statically referencing any classes/structs/variables/etc., referencing them all only by name/string instead, so anything using the VM can be accessed without a dependency on other packages (and without compile fails when something changes).
This is useful/important for writing unit tests that can break or go out of date, without breaking an entire suite of unit tests, and for maintaining permanent backwards compatibility through multiple engine/game codebase updates, and for general debugging.
Operator roles: (... is shorthand for an FVMReflection instance)
- FVMReflection(Object): Initialize a reflection helper, pointing to the specified object, for use with operators
- FVMReflection(FStructOnScope): Initialize a reflection helper, pointing to the struct within the specified FStructOnScope
- FVMReflection(VMReflection): Initialize a reflection helper, by copying another reflection helpers current state
- ...->"Property": Point the reflection helper, to the specified property
- (...->"Array")["Type"][Element]: Array property element (also specifies the inner array type, for verification)
- (Type)(...): Cast data the reflection helper points to, to specified type (only way to access data)
- (Struct*)(void*)(...)["Struct"]: Special cast (void*), for accessing structs (also specify struct type [], for verification)
- (..., &bError): Outputs to bError, whether any error was encountered this far into parsing
- (..., &ErrorString): As above, excepts outputs a string containing the entire reflection history and error text
Not yet implemented:
- (...->*"Function")("Parm1", etc.): Execute the specified function, with the specified parameters. Might not get implemented.
Example: FGuid* ItemGuid = (FGuid*)(void*)(((FVMReflection(UnitPC.Get())->"WorldInventory"->"Inventory"->*"Items") ["FFortItemEntry"][0]->"ItemGuid")["FGuid"]);
Setting function parameters: The FFuncReflection class allows you to easily set the parameters for functions, using reflection; this is useful for RPC's, as well as for general local functions called using ProcessEvent etc..
For example: FFuncReflection FuncRefl(PlayerStateObj, TEXT("UndoRemoveCardFromHandAtIndex"));
FVMReflection(FuncRefl.ParmsRefl)->"CardData"->"CardGuid"->*"A" = 1;
PlayerStateObj->ProcessEvent(FuncRefl.GetFunc(), FuncRefl.GetParms()); Example of how the reflection helper makes code more succinct:
New code (reflection helper): // Reflection for AFortPlayerController->QuickBars AActor* QuickBars = (AActor*)(UObject*)(FVMReflection(UnitPC.Get())->*"QuickBars");
// Reflection for AFortPlayerController->WorldInventory->Inventory->Items->ItemGuid FGuid* EntryItemGuidRef = (FGuid*)(void*)(((FVMReflection(UnitPC.Get()) ->"WorldInventory"->"Inventory"->"Items")["FFortItemEntry"][0]->"ItemGuid")["FGuid"]);
...
Old code (manual reflection): // Reflection for AFortPlayerController->QuickBars FObjectProperty* QuickBarsProp = FindFProperty
// Reflection for AFortPlayerController->WorldInventory->Inventory->Items->ItemGuid FObjectProperty* WorldInvProp = FindFProperty
void* InvItemsEntryRef = ((InvItemsArray != NULL && InvItemsArray->Num() > 0) ? InvItemsArray->GetRawPtr(0) : NULL); FStructProperty* InvItemsEntryProp = CastField
...
if (InvItemsArray != NULL) { delete InvItemsArray; } Currently supported fields (field list taken from UEd class viewer) - Field - Enum - UserDefinedEnum - Property readwrite - ArrayProperty readonly - BoolProperty arraycheck
- DelegateProperty
- InterfaceProperty
- MulticastDelegateProperty readwrite - NameProperty arraycheck assign done - NumericProperty readwrite - ByteProperty arraycheck assign readwriteupcast - DoubleProperty arraycheck assign readwrite - FloatProperty arraycheck assign readwriteupcast - Int16Property arraycheck assign readwriteupcast - Int64Property arraycheck assign readwrite - Int8Property arraycheck assign readwriteupcast - IntProperty arraycheck assign readwriteupcast - FInt16Property arraycheck assign readwriteupcast - FIntProperty arraycheck assign readwriteupcast - FInt64Property arraycheck assign
- ObjectPropertyBase readwrite - SoftObjectProperty assign inherited - SoftClassProperty inherited
- LazyObjectProperty readwrite - ObjectProperty arraycheck assign inherited - ClassProperty inherited inherited readwrite - WeakObjectProperty readwrite - StrProperty arraycheck assign readwrite - StructProperty arraycheck readwrite - TextProperty arraycheck assign readwrite - Struct readwrite - Class
- BlueprintGeneratedClass
- AnimBlueprintGeneratedClass
- GameplayAbilityBlueprintGeneratedClass
- ScriptBlueprintGeneratedClass
- WidgetBlueprintGeneratedClass
- LinkerPlaceholderClass
- Function
- DelegateFunction
- LinkerPlaceholderFunction readwrite - ScriptStruct
- UserDefinedStruct
- AISenseBlueprintListener
Other: readwrite - Static Arrays done - Static object array, context/object access (i.e. using ->* on object array elements) done - Dynamic object array, context/object access done - Struct context access ? - Struct object access done - Struct property casting
This would be extremely nice to have, as a debug command; could even use the reflection helper to parse while typing, adding VAX-like autocomplete suggestions while typing on the console, for this class of console commands.
Beyond the scope of the unit test tool, but (with much of the legwork done below) it's low hanging fruit, that'd make for a nice feature. If you (eventually) add autocomplete to the unit test tool log window, this would be the next logical feature. Used for specifying the warning level, for reflection helpers