Hello, help a newbie understand the basics. In a new project, I created two C++ classes: Cube and MyPawn.
Cube.cpp
ACube::ACube()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you dont need it.
PrimaryActorTick.bCanEverTick = true;
static ConstructorHelpers::FObjectFinder<UStaticMesh>C(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube'"));
UStaticMeshComponent* Cube = CreateDefaultSubobject<UStaticMeshComponent>("Cube");
Cube->SetupAttachment(RootComponent);
Cube->SetWorldScale3D(FVector(0.4f));
Cube->SetStaticMesh(C.Object);
UStaticMeshComponent* miniCube = CreateDefaultSubobject<UStaticMeshComponent>("miniCube");
miniCube->SetupAttachment(Cube);
miniCube->SetRelativeLocation(FVector(0.f, 0.f, 100.f));
miniCube->SetWorldScale3D(FVector(0.5f));
miniCube->SetStaticMesh(C.Object);
}
MyPawn.cpp
// Called when the game starts or when spawned
void AMyPawn::BeginPlay()
{
Super::BeginPlay();
ACube* MyCube = GetWorld()->SpawnActor<ACube>(FVector(15.f, 150.f, 70.f), FRotator(0.f));
}
How to remove the miniCube component?
How to check if the miniCube component does not exist, then create it?
How to detach a miniCube component?