Hey there,
I’m trying to deal with the Programming Quick Start, but the cube doesn’t appear.
After some tests, the problem looks to be from the line below:
static ConstructorHelpers::FObjectFinder<UStaticMesh> CubeVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube"));
I searched in the forums, but I cannot find something working.
This is my class constructor:
AFloatingActor::AFloatingActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
VisualMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
VisualMesh->SetupAttachment(RootComponent);
static ConstructorHelpers::FObjectFinder<UStaticMesh> CubeVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube"));
if (CubeVisualAsset.Succeeded())
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, "CubeVisualAsset.Succeeded()");
VisualMesh->SetStaticMesh(CubeVisualAsset.Object);
VisualMesh->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
}
else {
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, "else");
}
}
When running in editor, the “else” debug statement is returned.
I tried to use many different mesh references:
static ConstructorHelpers::FObjectFinder<UStaticMesh> CubeVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> CubeVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cube"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> CubeVisualAsset(TEXT("'/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube'"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> CubeVisualAsset(TEXT("/Script/Engine.StaticMesh'/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube'"));
But nothing worked. When I manually apply the Static Mesh, it’s working.
Thank you.