I think I’ve gotten pretty close – I think I’ve figured out how to make the runtime transient class, and how to grab a reference to the property itself. However, I haven’t figured out how to set the property.
This is what I have so far. It compiles and runs, but when the AnimInstance is actually created, the property value is still null, instead of the value I wanted to assign.
UClass* templateClass = UAnimCopyOrRetargetInstance::StaticClass();
FName genClassName = FName(FString::Printf(TEXT("gen_%s_from_%s"), *templateClass->GetName(), *skeleton->GetName()));
UClass* genClass = NewObject<UClass>(GetTransientPackage(), genClassName, RF_Public | RF_Transient);
genClass->ClassFlags |= CLASS_Transient;
genClass->PurgeClass(false);
genClass->PropertyLink = templateClass->PropertyLink;
genClass->ClassAddReferencedObjects = templateClass->ClassAddReferencedObjects;
genClass->SetSuperStruct(templateClass);
genClass->StaticLink(true);
genClass->AssembleReferenceTokenStream();
FProperty* prop = genClass->FindPropertyByName(GET_MEMBER_NAME_CHECKED(UAnimCopyOrRetargetInstance, mCopySource));
FObjectPtrProperty* objPtrProp = Cast<FObjectPtrProperty>(prop);
HV_ASSERT(objPtrProp);
objPtrProp->SetObjectPropertyValue_InContainer(genClass, rootSkmComp);
genClass->Bind();
objPtrProp->SetObjectPropertyValue_InContainer(genClass, rootSkmComp);
objPtrProp->SetObjectPropertyValue_InContainer(genClass->GetDefaultObject(), rootSkmComp);
subComponent->SetAnimInstanceClass(genClass);
Context: I made a native AnimInstance class that generates a CopyPoseFromMesh or RetargetPoseFromMesh, depending on what’s required.
Originally, I just set the AnimInstanceClass, then called RegisterComponent(), grabbed the AnimInstance instance, and set the value I wanted. However, that AnimInstance value isn’t being persisted from editor to PIE, so I suspect the AnimInstance is being recreated from its class at runtime, which seems to imply that I need to make a new derived class that contains the value I want as part of its default properties.
For reference, I’ve also tried assigning the value directly to the CDO instance, but that doesn’t seem to persist the value either