Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.14
more ▼

asked Feb 28 '17 at 10:20 PM in C++ Programming

avatar image

8 3 6 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Mar 02 '17 at 05:19 PM

avatar image

26 2 1

avatar image BaronVonSatchel Mar 02 '17 at 09:07 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question