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. 

Attaching a StaticMeshComponent to A SceneComponent

I am trying to to achieve the following hierarchy:

Pawn -> StaticMeshComponent (Root Component) -> SceneComponent A -> StaticMeshComponent B

In other words: My pawn has a mesh-representation, and my scene component A also has one with B. I use the following code to achieve this in the SceneComponent A:

         bool bActivated = false;
         UStaticMeshComponent* mesh;
     // Sets default values for this component's properties
     // Called when the game starts
     virtual void BeginPlay() override;
     // Called every frame
     virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;

Where UstaticMeshComponent* mesh ist the pointer for B. I initialize it in the constructor:

     // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
     // off to improve performance if you don't need them.
     bWantsBeginPlay = true;
     PrimaryComponentTick.bCanEverTick = true;
     mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("mesh"));
     // ...

This is the result:

alt text

Both A and B are children of the RootComponent, not B child of A. I can edit the mesh of B through A (were B is accessible and editable), but not its material. When I select it I cant change its properties, because the engine says it is inhereted and must be declarde with Uproperty (which I did). It does not render in editor, but when I hit play it does. When I hover over it, it says "Introduced in: Unknown native source (via C++ code)" which makes absolutely no sense to me.

So I would like to know how to fix this and if my approach to giving both A and the pawn a mesh is right (I didnt find a way to include the mesh in the A itsself)

I have tried this in 4.10.4 and 4.12.3

Thank you for your help!

Product Version: Not Selected
problem.jpg (275.7 kB)
more ▼

asked Jun 19 '16 at 03:48 PM in C++ Programming

avatar image

1.2k 46 29 59

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

1 answer: sort voted first

mesh->SetupAttachment(Module); is what you are looking for.

more ▼

answered Jan 24 '17 at 01:57 AM

avatar image

31 1 2 2

avatar image pulp_user Jan 24 '17 at 10:29 AM

I should have closed this question a while ago since I found the answer, but yours is of course correct! One thing to add: SetupAttachment(Module) only works for components that have not yet been registered by RegisterComponent(). If it has been registered, one has to use AttachToComponent(Module)

(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