Best Practices: Extend mesh component class or add as child

I need to make an Actor Component class that has a static mesh as well as some other functionalities. Pretty standard stuff I should think. I’m just wondering whether it’s better for my component to extend the mesh component class (StaticMeshComponent in this case) or to add the mesh component as a child of my component. Either would work but I’m curious which is preferred, or if it matters at all.

I would usually recommend against extending the concrete engine component classes in this way.
Using composition rather than inheritance will usually be the more flexible and future-proof approach.

In fact, depending on what extra functionality you need, you might later find that it could work not only with a Static Mesh Component, but might be fine with any other Primitive Component, or with Skeletal Meshes, or even with multiple meshes. Trying to later adapt your class to do those things will be a lot easier if it just references the mesh rather than extends it.

The exception would be if you’re really trying to do something that specifically needs to access or modify the Static Mesh Component’s internal data, so that your class really is a new kind of Static Mesh - but I don’t think that’s likely what you want. Generally if you want to create or manipulate vertices and such you would derive from UMeshComponent or UPrimitiveComponent instead of UStaticMeshComponent.

Thanks! I have another class which extends the MeshComponent because it needs access to the mesh data to perform buoyancy calculations on each triangle, but since this is a more “normal” usage I wasn’t sure which is optimal.