**What I am trying to achieve: ** I am trying to call a blueprint function (if it exists) and get it’s return parameter. Essentially, I’d like to have a map of { “GetPlayer”, “ActualGetPlayerFunctionName” }. Now I am sure that you cannot store function pointers in an array or map, which would make this so much simpler.
I am calling
Testing
and returns a string with example text.
if (!IsValid(this))
{
return;
}
UFunction* func = this->GetClass()->FindFunctionByName(FName("Testing"));
if (func == nullptr)
{
GEngine->AddOnScreenDebugMessage(12332, 10.0, FColor::Red, "Could not find Function 'Testing'!");
return;
}
FStructOnScope FuncParam(func);
FStrProperty* StrReturnValue = nullptr;
FString Value;
for (TFieldIterator<FProperty> It(func); It; ++It)
{
FProperty* Prop = *It;
if (Prop->HasAnyPropertyFlags(CPF_ReturnParm | CPF_OutParm))
{
GEngine->AddOnScreenDebugMessage(12332, 10.0, FColor::Red, "Found Return Value!");
FStrProperty* StrProperty = CastField<FStrProperty>(Prop);
if (StrProperty)
{
StrReturnValue = StrProperty;
}
}
}
this->ProcessEvent(func, FuncParam.GetStructMemory());
if (StrReturnValue != nullptr && IsValid(func))
{
GEngine->AddOnScreenDebugMessage(12331, 10.0, FColor::Red, "StrReturnValue is valid!", false);
Value = StrReturnValue->GetPropertyValue_InContainer(func);
if (Value.IsEmpty())
{
GEngine->AddOnScreenDebugMessage(12331, 10.0, FColor::Red, "Value is Empty!", false);
}
else
{
FString Text = "Length of Value is: " + FString::FromInt(Value.Len());
GEngine->AddOnScreenDebugMessage(12331, 10.0, FColor::Red, Text, false);
UE_LOG(LogTemp, Warning, TEXT("%s"), *Value);
}
}
So I can get the return property and cast it to a FStrProperty successfully. The problem is that I cannot access the value. This is where the documentation and source code is vague on the matter.
The source code describes
GetPropertyValue
as retrieving the value from an address, and
GetPropertyValue_InContainer
describes it as retrieving the value from a container.
I don’t understand where the value is stored, and how to get it. Shouldn’t the value be stored in the FStrProperty? (The blueprint function returns a string)
I keep getting access violation and GetOwner<UClass>() errors, and sometimes no error at all, but just garbage memory(Possible a memory leak).
I launched in DebugGame Editor and Visual Studio Debugger. The problem is accessing the value.
Thanks all,