Hi! I’ve been trying to make a console for a school project using Unreals reflection. It works by referencing blueprint function libraries in a settings panel, and then calling them using UObject::ProcessEvent.
Now, the problem is that every function made in Blueprint in these function libraries autogenerate a UObject* “__WorldContext” parameter, which I can’t find a clean way to get and fill. The current solution found below compares the FNames, but that is something I really despise as any whacky designer could rename the variable in Blueprint.
for (TFieldIterator<FProperty> It(Function); It && (It->PropertyFlags & (CPF_Parm | CPF_ReturnParm)) == CPF_Parm; ++It, NumParamsEvaluated++)
{
FProperty* PropertyParam = *It;
checkSlow(PropertyParam);
// @TODO: REPLACE MAGIC STRING CONSTANT
const static FName WorldContextParam = FName(TEXT("__WorldContext"));
if (It->GetFName() == WorldContextParam) //executes if this is the WorldContext parameter
{
FObjectPropertyBase* Op = CastField<FObjectPropertyBase>(PropertyParam);
if (GEngine && Op && this->IsA(Op->PropertyClass))
{
// Fills the first found local player as the WorldContext.
APlayerController* Player = GEngine->GetFirstLocalPlayerController(GetWorld());
Op->SetObjectPropertyValue(Op->ContainerPtrToValuePtr<uint8>(Parms), Player);
UE_LOG(LogTemp, Warning, TEXT("[WRLD]: %s %s %s"), *Op->GetCPPType(), *Op->GetName(), Op->GetObjectPropertyValue(Parms) ? TEXT("true") : TEXT("false"));
continue;
}
}
}
Is there any good way to get hold of this parameter in builds? Just saving the last FProperty found would make C++ commands annoying as almost every other C++ function in the engine has WorldContextObject as the first parameter, and accessing the WorldContext from the UFUNCTION metadata sadly isn’t an option…