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.