Step 4.
line: if((USceneComponent* ExistingRootComponent = GetRootComponent()) has one extra scope at the beginning after if statement.
line: static ConstructorHelpers::FObjectFinder CubeVisualAsset(TEXT(“/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube”)); doesn’t load cube.
Question how to fix this line and another question: is an argument correct CreateDefaultSubobject(TEXT(“Mesh”)); ?
I have this problem too)
But if you want to solve this problem, you need to go down this page
And you will see the difference
VisualMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
VisualMesh->SetupAttachment(RootComponent);
static ConstructorHelpers::FObjectFinder<UStaticMesh> CubeVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube"));
if (CubeVisualAsset.Succeeded())
{
VisualMesh->SetStaticMesh(CubeVisualAsset.Object);
VisualMesh->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
}
This code at the end of the documentation
But this code at the beginning of the documentation
if((USceneComponent* ExistingRootComponent = GetRootComponent())
{
VisualMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
VisualMesh->SetupAttachment(RootComponent);
static ConstructorHelpers::FObjectFinder<UStaticMesh> CubeVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube"));
if (CubeVisualAsset.Succeeded())
{
VisualMesh->SetStaticMesh(CubeVisualAsset.Object);
VisualMesh->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
}
}
Something like this)
1 Like
Thank you very much.
It’s working.
Really strange, they just removed the if statement and it works.