How can I access to Description of a BP Variable in C++?

I have a C++ Actor class (that inherit from AActor). Some Actor BP subclass my C++ actor. I doing some introspection on FProperty in C++ => How can I access to the variable description (ie. the text used for the variable tooltip) that may have been entered in BP?

I think you just have to add a comment right above the UPROPERTY, that shows up as the tooltip in editor (not 100% sure)

This is not in the FProperty framework.
Blueprint variables are stored in the Blueprint skeleton, more precisely in UBlueprint->NewVariables. They are a struct of type FBPVariableDescription. In this struct there is an array of metadata entries (of type FBPVariableMetaDataEntry). This is where the description is stored.
Sample code :

UBlueprint* Bp = LoadObject<UBlueprint>(nullptr, TEXT("/Game/Haiyaaa.Haiyaaa"));
for (auto& Var : Bp->NewVariables)
{
    UE_LOG(LogTemp, Log, TEXT("Variable: %s"), *Var.VarName.ToString());
    for (auto& Item : Var.MetaDataArray)
    {
        UE_LOG(LogTemp, Log, TEXT("  - %s = %s"), *Item.DataKey.ToString(), *Item.DataValue);
    }
}

The metadata key for description is “tooltip”.

Note that the UBlueprint object is entirely stripped out of assets when cooking, so all this data is unavailable in shipping build.

Not yet found how to move from a FProperty to the BP description if the property is not native (ie. BP variable). Stay tuned.

The Owner of the FProperty should be the UClass (UBlueprintGeneratedClass for blueprints).
Then you can go back to the blueprint via UClass->ClassGeneratedBy.
Then you’ll probably have to iterate that “NewVariables” array until you find a match by name.

Something like this :

// FProperty* Prop;
if (auto Class = Prop->GetOwner<UClass>())
{
    if (auto Bp = Cast<UBlueprint>(Class->ClassGeneratedBy))
    {
        for (auto& Var : Bp->NewVariables)
        {
            if (Var.VarName == Prop->GetFName())
                return Var.GetMetaData("tooltip");
        }
    }
}

Works fine. Thanks.

Damned. It works but only WITH_EDITOR, not in runtime.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.