Download

[SOLVED] Attach Mesh On Actor In Code

Hello all.

I am trying to attach a mesh directly at C++ side but the mesh is not showing up. (4.18.3)
Here is my code and a screencap.
Can you guess what is the problem ?
Thanks.

,h


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MeshedBase.generated.h"

UCLASS()
class TOKKA_API AMeshedBase : public AActor
{
    GENERATED_BODY()

public:    
    // Sets default values for this actor's properties
    AMeshedBase(const FObjectInitializer& ObjectInitializer);

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

public:    
    // Called every frame
    virtual void Tick(float DeltaTime) override;

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SimpleThings", meta = (AllowPrivateAccess = "true"))
    class UStaticMeshComponent* BaseMesh;


};



.cpp


// Fill out your copyright notice in the Description page of Project Settings.

#include "MeshedBase.h"
#include "Components/StaticMeshComponent.h"
#include "UObject/ConstructorHelpers.h"


// Sets default values
AMeshedBase::AMeshedBase(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
     // 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;

    BaseMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));
    BaseMesh->SetupAttachment(RootComponent);
    static ConstructorHelpers::FObjectFinder<UStaticMesh> BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'"));


}

// Called when the game starts or when spawned
void AMeshedBase::BeginPlay()
{
    Super::BeginPlay();

}

// Called every frame
void AMeshedBase::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

}




SOLVED:

https://answers.unrealengine.com/que…r-in-code.html