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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

C++ - array of mesh components, how to


How to correctly keep a couple of logically related mesh components in my class? (think sides of a dice that I want to be separate meshes)

(In the example below I use a UCustomMeshComponent which inherits from UMeshComponent) It did work for me either by doing:

 TSubobjectPtr<UCustomMeshComponent> SphereMesh1;
 TSubobjectPtr<UCustomMeshComponent> SphereMesh2;


 TArray<TSubobjectPtr<UCustomMeshComponent> > Sides;

However the latter one has some issues - for example cannot add an UPROPERTY() tag to it, as it crashes the engine (not being able to cast TArray to a property) and causes my custom meshes to disappear after I go to play mode and then exit from it. The first one on the other hand is not very versatile...

Or maybe there is a better way to do it?

Product Version: Not Selected
more ▼

asked Mar 25 '14 at 09:25 PM in C++ Programming

avatar image

291 16 19 248

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

2 answers: sort voted first


if it is always 6 sides you can use a static array

 TSubobjectPtr < UCustomMeshComponent > Sides[6];



 struct FSubObjStruct
     TArray < TSubobjectPtr < UCustomMeshComponent > > Comps;
     int32 GetCount() const
         return Sides.Num();

 //now you can use UPROPERTY()
 FSubObjStruct Sides;


 Sides.Comps.Add(new subobj);

more ▼

answered Mar 25 '14 at 09:30 PM

avatar image

10.6k 446 345 1088

avatar image fszczemton Mar 25 '14 at 09:39 PM

Thanks, great answer, that's exactly what I needed.

avatar image AlexYopp Oct 06 '15 at 11:17 PM

I'm attempting to do something similar, but my objects aren't actually being exposed to the editor. When I try

 UPaperSpriteComponent* DoorSprite[9];

...the first object is exposed, but none of the rest are. If I instead try to expose them individually, none of them are:

 for (uint8 i = 0; i < _NumberOfDoors; i++){
      DoorSprite[i] = CreateDefaultSubobject<UPaperSpriteComponent>(*(FString::Printf(TEXT("DoorSprite_%u"), i)));
      DoorSprite[i]->AttachTo(Root, NAME_None, EAttachLocation::KeepWorldPosition);
avatar image Mtimofeev Apr 23 '16 at 07:49 PM

were you ever able to find a solution? I am facing the same issue, can't have a dynamic array of exposed meshes.

avatar image Thumper Nov 01 '16 at 02:32 PM

TSubobjectPtr is deprecated so this whole answer no longer works. What would be the correct way to do this now using CreateDefaultSubobject?

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

Why not create the array variable in the derived blueprint and make a function in the c++ class that takes the array in from the blueprint and then call that function in the blueprint?

more ▼

answered Jan 20 '15 at 08:11 AM

avatar image

Commander Shepard
802 62 82 219

(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