How to modify/replace a Blueprint object's reference with c++?

I’m currently working on a plugin to process uasset files. The plugin will export an asset, e.g., a particle system, a material, or a blueprint, to another folder. Different from unreal’s built-in migrate feature, our plugin will re-organize file structures. So reference map would break after copying the files.

After reading the engine’s source code, we have some code like this

TMap<UObject*, UObject*> ReplacementMap;
for (int i = 0; i < SrcObjects.Num(); ++i)
    {
        FString SrcObjClass = SrcObjects[i]->GetClass()->GetName();           
        ReplacementMap.Add(SrcObjects[i], TempObjects[i]);
    }

FArchiveReplaceObjectRef<UObject> ReplaceAr(TempObject, ReplacementMap, true, true, true);

It works very well for all types (particle system, niagara system, textures, materials, etc.) with only one exception: Blueprint.

The code will not replace reference for UBlueprint* at all. However, for objects insides the blueprints, the code works.

For example, B->C->D-E, B is a Blueprint object, C D E are materials or textures. Aftering copying uassets and running the code above, B still points to old C D E, C will point to new D, D will point to new E.

Which API should I use to replace Blueprint’s reference?

1 Like