How can I reparent blueprint parent class in C++?

Hi, I want to know how can I reparent blueprint parent class by code the class of a blueprint asset like in class settings in the blueprint viewport, like the picture below but in C++:

Thanks for the help in advance.

I interpret your question as:

In C++ code, you have two base classes: BaseClassA and BaseClassB.

DerivedClassC is derived from BaseClassA.

You want DerivedClassC to be a child of BaseClassB instead.

If that is a correct interpretation then in the existing DerivedClass.h header will be a line:

Class DerivedClassC : BaseClassA

If you change the reference from BaseClassA to BaseClassB then you will have successfully re-parented the DerivedClassC.

You will then have to ensure that any existing code you have written elsewhere that uses BaseClassA functionality when dealing with instances of DerivedClassC are updated if that identical functionality and call signature does not exist in BaseClassB.

Also any variable declarations, template calls ("") and casts ("= (BaseClassA)") etc. would need to be updated to refer to BaseClassB.

Could be a messy task if you are editing a big project.

I just did it creating a function that reparent the blueprint by code like this:

//Here the parent class will be changed (ChosenClass is a UClass* and BlueprintObj is a UBlueprint*)
BlueprintObj->ParentClass = ChosenClass;

//Here I just Compile the blueprint by code
Helpers::CompileBlueprint(BlueprintObj);

//And here the blueprint will be reload because it changed its parent class
FBlueprintEditorUtils::RefreshAllNodes(BlueprintObj);
FBlueprintEditorUtils::MarkBlueprintAsModified(BlueprintObj);

I answer my own question with the solution, thanks for the help!