I have two options for you. First is the way I suggested already. It’s the answer usually given:
…
Second Option:
if (USkeletalMeshComponent *Mesh = MyActor->FindComponentByClass<USkeletalMeshComponent>())
{
if (UAnimInstance *AnimInst = Mesh->GetAnimInstance())
{
UFloatProperty* MyFloatProp = FindField<UFloatProperty>(AnimInst->GetClass(), AnimPropName);
if (MyFloatProp != NULL)
{
float FloatVal = MyFloatProp->GetPropertyValue_InContainer(AnimInst);
MyFloatProp->SetPropertyValue_InContainer(AnimInst, 180.0f);
FloatVal = MyFloatProp->GetPropertyValue_InContainer(AnimInst);
}
}
}
I put a way to get and to set in there.
This technique also works with regular blueprints, not just anim blueprints and with other types:
UBoolProperty* BoolProp = FindField<UBoolProperty>(MyActor->GetClass(), PropName);
if (BoolProp != NULL)
{
bool BoolVal = BoolProp->GetPropertyValue_InContainer(Actor1);
BoolProp->SetPropertyValue_InContainer(Actor1, true);
}
The names are just simple FName data types:
FName PropName = TEXT("MyBoolVariable");
FName AnimPropName = TEXT("MyFloatVariable");
Here’s the source I got it from: