How to edit Blueprint components from C++?

Hello,

I’m working on a import plugin for UE 5.0 who create a ready to use actor on file import.

In my factory I have my FactoryCreateFile method to create my actor on import.
It can be simplified like this:

< ... doing stuff ... >

AMyActor* Actor = NewObject<AMyActor>();
Actor->Prepare(XMLDescription, ActorName); // Setup my complete actor with different components

// Save to Content Browser
FKismetEditorUtilities::FCreateBlueprintFromActorParams Params;
Params.bOpenBlueprint = false;
Params.bReplaceActor = false;
UBlueprint* Blueprint = FKismetEditorUtilities::CreateBlueprintFromActor(ActorName, BluePrintPackage, Actor, Params);
FAssetRegistryModule::AssetCreated(Blueprint);

The method Prepare() will dynamically setup the Actor with different components to fit an XML description from the imported file.

The problem is now I’m working on the re-import part. I would like to update this existing actor.

I tried to use FKismetEditorUtilities::ReplaceBlueprint(ExistingBlueprint, NewBlueprint) creating a new actor and replacing the first one. But the old one is not deleted. And after a reboot of Unreal the actors in my level(s) are using the first one again.

Today I tried to access to the blueprint generated class to edit it and compile the BP again.

< ... doing stuff ... >

UBlueprint* Blueprint = FMyUtils::LoadBPIfExists(BlueprintPath);
if (Blueprint != nullptr) {
	AMyActor* BlueprintValues = Blueprint->GeneratedClass.Get()->GetDefaultObject<AMyActor>();

	// Here I am unable to find any reference to my previously created components
	// So I tried to setup my actor again like in import
	Actor->Prepare(NewXMLDescription, ActorName);

	// And now compile the changes
	FCompilerResultsLog LogResults;
	FKismetEditorUtilities::CompileBlueprint(Blueprint, EBlueprintCompileOptions::None, &LogResults);
	Blueprint->MarkPackageDirty();
}

The problem is, now with this code when I open my updated actor all my components are now duplicated. There is the old ones and the new ones. The existing components should be accessible from somewhere in my re-import code if Unreal is able to find them in the BP editor.

There is a way to completely purge my existing BP/actor before populating it again ?
Or how can I edit the different components dynamically created ?