Navigation
Unreal Engine C++ API Reference > Plugins > NetcodeUnitTest
Syntax
&42;FObjectProperty &42; WorldInvProp
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 /**