Want to change value of variable(FLiveLinkSubjectName) in a Blueprint in C++

Hello! :wink:
After many attempts, I succeeded in accessing an AnimBP variable (type FLiveLinkSubjectName) using FindPropertyByName(), FProperty, and FStructProperty.
But I still have a problem that I haven’t been able to solve.

I want to change the value of FLiveLinkSubjectName.Name. I tried to change FProperty* or FStructProperty* to FLiveLinkSubjectName* type, but all failed. The code below is the most recent attempt, and crash occurred.
How can I change the value of FLiveLinkSubjectName type variable in AnimBP?..

void AMain::TempFunction(UObject* AnimBP, FString TargetLiveLinkSubjectName, FString NewName)
{
    if (AnimBP)
    {
        UClass* AnimBPClass = AnimBP->GetClass();
        if (AnimBPClass)
        {
            FProperty* Prop = AnimBPClass->FindPropertyByName(FName(*TargetLiveLinkSubjectName));
            if (Prop)
            {
                FStructProperty* StructProp = CastField<FStructProperty>(Prop);
                if (StructProp)
                {
                    FLiveLinkSubjectName* LiveLinkSubjectName = reinterpret_cast<FLiveLinkSubjectName*>(StructProp);
                    if (LiveLinkSubjectName)
                    {
                        //crash!
                        LiveLinkSubjectName->Name = FName(*NewName);
                        UE_LOG(LogTemp, Warning, TEXT("!!!"));
                    }
                }
            }
        }
    }
}

After many attempts, I finally succeeded. I’m sharing in case anyone has the same problem as me :slight_smile:

void AMain::NeedToTestOne(UObject* AnimBP, FLiveLinkSubjectName NewSubjectName, FString TargetLiveLinkSubjectName)
{
	if (AnimBP)
	{
		if (UClass* AnimBPClass = AnimBP->GetClass())
		{
			if (FProperty* Prop = AnimBPClass->FindPropertyByName(FName(*TargetLiveLinkSubjectName)))
			{
				//not Prop->GetClass(), AnimBP is answer
				FLiveLinkSubjectName* PropPtr = Prop->ContainerPtrToValuePtr<FLiveLinkSubjectName>(AnimBP);
				if (PropPtr)
				{
					*PropPtr = NewSubjectName;
					UE_LOG(LogTemp, Warning, TEXT("%s'%s : %s"), *(AnimBP->GetFullGroupName(false)), *TargetLiveLinkSubjectName, *(PropPtr->Name.ToString()));
				}
			}
		}
	}
}
1 Like