How to replace a component with a different class (Same actor)

@smmehl0311’s method didn’t work for me, but it led to this solution.

  1. Call this function from a AssetActionUtility blueprint with the classes you want to convert from and to:
void UMyBlueprintLibrary::MigrateBlueprintComponents(UBlueprint *BPToMigrate, TSubclassOf<UActorComponent> OldClass, TSubclassOf<UActorComponent> NewClass) {

	if (BPToMigrate && BPToMigrate->SimpleConstructionScript) {
		USimpleConstructionScript* SCS = BPToMigrate->SimpleConstructionScript;
		const TArray<USCS_Node*>& ScsNodes = SCS->GetAllNodes();
		
		for (const auto ScsNode : ScsNodes) {
			UActorComponent* component = ScsNode->ComponentTemplate;
			
			if (component->IsA(OldClass)) {
				ScsNode->ComponentClass = NewClass;

				FObjectDuplicationParameters dup(component, component->GetOuter());
				dup.DestClass = NewClass;
				ScsNode->ComponentTemplate = CastChecked<UActorComponent>(StaticDuplicateObjectEx(dup));
			}
		}
	}
}
  1. Open the blueprint in question; you should see that the component’s type has changed! Now, rename the affected component(s). The new name can be anything; it’s the renaming itself that’s important.
  2. For every blueprint affected by the rename, including the original one (you can filter for Modified in the content browser) open it and do File->Refresh All Nodes. Without this step, attempts to access the component will return None.

Caveats: This only works for converting a component to a child class. Blueprints that inherit from the modified blueprint and have changed properties on the component might have those properties reset.

1 Like