x

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"

How do I attach two actors to another in C++?

Hi,

I am new to UE4 but not new to programming. (PLCs, Robots, Vision-Software and other automation stuff)

I started with the "Components and Collision" tutorial with no problem. For the further questions I made an Actor that Orbits around it's root. No problem so far. But I can't attach the collidig pawn to my Orbit. As I figured out you can use AttachToActor or UChildActorComponent. I couldn't get it to work with AttachToActor so I tried it as a UChildComponent.

My header:

 UChildActorComponent* Orbit;
 TSubclassOf<AOrbit> OrbitClass;

My constructor:

 Orbit = CreateDefaultSubobject<UChildActorComponent>(TEXT("Orbit"));
 Orbit->AttachTo(SphereVisual);
 Orbit->SetupAttachment(SphereVisual);
 Orbit->SetChildActorClass(OrbitClass);
 Orbit->CreateChildActor();

I tried with attach to and without but the orbit didn't show up. It works per drag and drop in the UE.

What's the failure and does it have to do with if it is registered?

Thanks for your help, Chris

Product Version: UE 4.21
Tags:
more ▼

asked Jan 20 '19 at 06:38 PM in C++ Programming

avatar image

RagingSea
1

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

1 answer: sort voted first

Hey Chris!

Because of reflection (and blueprint system) system construction time attachment reflected only at engine startup or when you create/inherit new blueprint class from this class.. (so in short c++ classes are created when you inherit a new BP class from it)

But since UChildActorComponent is just a component and his job to create a new actor, the newly created actor would be definitly not attached because it would be created at runtime i think :) (maybe you need reattach it after object is spawned)

Also you wont see UChildActorComponent* Orbit because you missing the reflection macro to make it visible in blueprint (you can read about here: https://wiki.unrealengine.com/UPROPERTY , and here: https://docs.unrealengine.com/en-US/Programming/UnrealArchitecture/Reference/Properties )

Should look like this

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components)
 UChildActorComponent* Orbit;

BTW ue4 has a huge component system, so if you dont want to use a whole new actor as orbit, you can use lot of other components, like ustaticmeshcomponent.. you can attach this components at construction time and you can work with them :)

more ▼

answered Jan 23 '19 at 03:06 PM

avatar image

AmphDev
1.5k 15 9 34

(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