AddChildActor via function C++

I’m not sure I did understand what you asked for, but maybe you are talking about this:

	// Create the root node
	DefaultSceneRoot = CreateDefaultSubobject<USceneComponent>(
		TEXT("DefaultSceneRoot"));
	RootComponent = DefaultSceneRoot;

	// Attach a camera to the parent node (here it's the root node)
	Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
	Camera->SetupAttachment(RootComponent);

In this example, the camera will have the same transform as its parent (the root node).

Documentation is here : https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/USceneComponent/SetupAttachment/index.html

Good luck.
Best regards.

Hello guys,

I’ve been trying to get versed with UE4 C++ now as I think I have become pretty familiar with blueprints. I made a game using blueprints and now I’m trying to replicate the same using C++. I’ve hit a roadblock and cannot find a proper solution.

Summarizing what I need is -

I have a Blueprint actor that I want to spawn in a C++ actor

I have set the blueprint actor in header files as this -

UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Obstacles)
		TSubclassOf<class AActor> MyObstacle;

I have initialized the same in the constructor like this -

static ConstructorHelpers::FObjectFinder<UBlueprint> My_Obstacle(TEXT("Blueprint'/Game/Blueprints/Obstacle_BPs/SimpleObs/BP_MyObstacle.BP_MyObstacle'"));
	if (My_Obstacle.Object) {
		MyObstacle = (UClass*)My_Obstacle.Object->GeneratedClass;
	}

Now, I also have defined and initialized three arrow components in my C++ Actor class like this.

Header -

// Definition of arrow components 

	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = SpawnPoints)
		UArrowComponent * LeftSpawn;
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = SpawnPoints)
		UArrowComponent * RightSpawn;
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = SpawnPoints)
		UArrowComponent * MiddleSpawn;

CPP -

MiddleSpawn = ObjectInitializer.CreateDefaultSubobject<UArrowComponent>(this, TEXT("MiddleSpawn"));
	LeftSpawn = ObjectInitializer.CreateDefaultSubobject<UArrowComponent>(this, TEXT("LeftSpawn"));
	RightSpawn = ObjectInitializer.CreateDefaultSubobject<UArrowComponent>(this, TEXT("RightSpawn"));	

What I want to know is how to add/spawn MyObstacle as a child actor on one of the above arrow components ON FUNCTION CALL, like in blueprint you have “AddChildActorComponent” Node which takes transform as one of the inputs and class as another one.

Apologies if I was not clear.

Simply, what I want is on an arrow component (Its transform to be more specific) that I created as above I want to add/spawn a child actor (Which is blueprint) through calling a function.

Basically this,

Ok, nvm I found an alternate to achieve what I wanted to do. Thanks for the answers though. Cheers.