Hello
I have a BP Actor-derived class (BP_MyActor)
It contains several BP components that define various behaviors.
For performance reasons (compute-heavy code), it is now time to move some of these components to C++. Let’s call such a component BP_MyComp.
However, since BP_MyComp is rather big, I do not want to delete it right away but I want, for some time, to be able to switch between the BP implementation and the in-progress C++ implementation.
Being a C++ programmer, my first thought was :
-
- let’s create an interface
IMyCompwhere I declare theBP_MyComppublic functions.
- let’s create an interface
-
- Make
BP_CompimplementIMyCompand reconnect the implemented interface events to their proper implementation (UE unfortunately does not “understand” this refactoring and tells me the existing function clash with the new interface ones… I have to rename the old functions and move their BP graph into the new interface event implementation graph)
- Make
This works OK. I can see my C++ defined interface and implement it.
Then, I wanted to remove the BP_MyComp statically defined component from BP_MyActor (the one that was added with the big green “+ Add Component” button in the actor BP editor) and turn the component into a variable.
The idea was to have a variable of type IMyComp and, at runtime, decide (on a flag or some .ini
setting) whether to instantiate the BP_MyComp or a new Cpp_MyComp, then assign the result to the IMyComp variable, then eventually dynamically add it by calling AddComponent on the actor.
It does not work.
It is simply not possible to declare a BP variable with an interface type. It works for BP interfaces, but not C++ interfaces. Unless I have missed a specific macro keyword.
How would you guys approach such a refactoring where BP code is gradually moved to C++ with A/B testing?
A base class maybe? Am I allowed to reparent BP_MyComp to a pure C++ base class and use it as the type of a property ?
I am confused by the way UE interfaces are meant to be used. This looks like such a basic pattern…
Thanks in advance!
