Replace a C++ Native Component with a Derived class

Hey, I’m trying to figure out how on earth to solve this gracefully -

I need to replace a Native Component with a Blueprint derived class.

Lets say we have:

class Foo  : public AActor {

    UBarComponent* ReplaceableComponent;
    public Foo() {
        ReplaceableComponent = CreateDefaultSubobject< UBarComponent>( 
            TEXT( "ReplaceableComponent" ) );

Now, if I blueprint my class Foo, in the left hand pane, I can see my Native Component registered.
But I want to replace this instance, for this blueprint only.

Say I have created another Blueprint based off of UBarComponent called BP_MyBarComponent.
The blueprint editor will not let me replace “ReplaceableComponent” with an instance of BP_MyBarComponent.

Has anyone figured out how to deal with this?

I tried setting the property to BlueprintReadWrite, and granting EditInlineNew to the component base class.
This allows me to set it via the blueprint variables in the editor, but when I compile it gets set to null again.

Hmm this could be tricky, I haven’t tried it before, but: CreateDefaultSubobject can take 2 classes in its template parameters like so:

template<class TReturnType, class TClassToConstructByDefault>
	TReturnType* CreateDefaultSubobject(FName SubobjectName, bool bTransient = false)

But you will need access to your class at compile time, so my best guess would be to do this using ConstructorHelpers, have you dealt with those? Look at a starter UE project template, and see how they define the default pawn class for example. You access the location of a blueprint in disk. Do the same for your blueprint (but do ClassFinder and get hold of Class, not Object). Feed that into your TClassToConstructByDefault parameter and see what happens?. Not sure though why you would want to do what you are trying to do. I guess, make sure your return type is of the native code type, so you can access your class in code. Anything created in the blueprint editor will not easily be accessible via code.