Refactor by moving BP components to C++

To move things to C++, I use implementation inheritance instead.
Yeah, I’m not a big fan of implementation inheritance, but it’s the Way Of Life in Unreal Engine.

So, assuming I wanted to port a Component blueprint to C++, I’d create a new ActorComponent or SceneComponent called something like MyComponent in C++. It might even be empty to begin with, but it would inherit from whatever base Unreal component class your BP component is inheriting from.

Then I’d go into the component definition in Blueprint and choose “File → Reparent” to make it inherit from my MyComponent instead of the base component type. This should work like a no-op. Make sure you can compile and run at this point.

Now, you can move things from your BP class into your MyComponent C++ class, one field or function at a time if you want. Declare it in C++, remove it from BP, compile and run to make sure it works, repeat.

At some point, you’ve moved all your blueprint functionality into the C++ class, and the blueprint class is empty. Now you can go to all blueprints that use the blueprint-component-class, and reparent them to inherit directly from your MyComponent instead of the blueprint component class.

Finally, you can remove the blueprint class at this point.

2 Likes