How to move component from parent class to derived classes

Hi,

I was wondering how I would be able to delete a component in a parent class without deleting it in the child classes.



image

In this case, I’d want to delete “SomeMesh” in the ActorParent, but still have it be present in ActorChild, just as a non-inherited component instead. Like so:
image




My first idea was to just manually go through and copy the component in the child classes before then going back and deleting it in the parent, but duplicate/copypaste on inherited components seems to copy the default of the parent and not any of the changed values of the derived class.

Thank you.

Hey there @rokenrock! The way inheritance works, all changes in the parent will propagate to the children naturally. In Blueprints this is relatively immutable. If need be, whenever you need to make a large enough change to the structure of a parent class, you may need to look into making multiple sub classes. Ie Actor Parent only having the default scene root and logic that will apply to all children and grandchildren, then a subclass of children that do have a static mesh and then logic for all children that have that static mesh, then handle your grandchildren how you’d like personalizing their SM and personal logic. This way you can utilize a child without the SM and one with it if need be. You aren’t limited to one subclass either, you can make any amount of them.

Yes, that is exactly what I’ve done for everything except this one static mesh component. It’s been around since I first created this parent class. That’s why I want to get it out of the parent class- it’s been bugging me.


Most subclasses of this base class do use the static mesh, but most also use multiple others, and some don't use it at all, so there isn't much of a point in having one in the parent class- especially considering every subclass has wildly different settings on said mesh.

That is why I am trying to push it into the children that do actually use it.


Basically, I want to remove it from only the parent. But as you said, changes to the parent affect the child immediately- deleting it in the parent will delete it in the child. I don't mind if I need to do it manually, but I would prefer not to have to copy every single changed variable by hand.

Sure is a pain that copy/pasting an inherited component doesn’t duplicate its changed settings.
Is there maybe a way to copy every variable at once from one component to another? That would solve my issue.

I don’t know think there’s a more optimal way to do this with BPs specifically. Changing the parent of all the subclasses could get you the effect but it would also swill wipe out all the data attached to the previous portion of those components. I was going to see if copying and pasting the component would retain it’s settings but apparently not like you mentioned. Hopefully someone has a less manual way to pull this off.

Yeah I hope so. If not, at least I’ve got the undo button to see what’s been changed.

1 Like

I know it’s an old thread, but for future ppl finding this thread.

The only way I found out to easily and quickly change parent class of components within blueprints, is by copying the component to notepad or other text editor, change the class here in the XML like structure to a child class you created. Just find and replace the text string that defines the component. I had to do it twice on each component, Once in ‘Begin Object Class’ and once in exportPath.

When those 2 strings are changed, copy and paste the component back to your blueprint, but make sure you delete the original component first.

And voila, your component now inherites your custom subclass.

1 Like