[Support][Help] C++ derived Blueprint's component properties not carrying into instance.

I have this problem where if i create an Actor class in C++ and add components to it, then create a blueprint from that class and edit the properties of those components on the blueprint editor, when i create an instance the properties are not applied, even when the details window shows it has the values set on the blueprint editor.

Example:

MyActorClass.h



UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
        UStaticMeshComponent* StaticMesh;


MyActorClass.cpp
Constructor:



StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Static Mesh"));


Then I assign a mesh in the blueprint editor, and it shows ok in the viewport tab, but when i add an instance to the scene, there is nothing visible, but the details window says it has the selected mesh.

Another example, with a WidgetComponent, i try to adjust its relative position in Blueprint editor, but the instance always used the default. I had to set it in the C++ class’ BeginPlay method.

I tried to look into the ACharacter class to see how they do it, they declare the StaticMesh UPROPERTY with the same specifiers i do, I don’t know what the difference is. I appreciate any help.

Make sure your Static Mesh is attached to something in C++ constructor after creating it.


StaticMesh->SetupAttachment(GetRootComponent());

.h
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Stuff”) UStaticMesh* Mesh;

private:
UPROPERTY() UStaticMeshComponent* StaticMeshComponent;

Also, try to expose a UStaticMesh instead of the component to BP then in OnConstruct or BeginPlay method: StaticMeshComponent->SetStaticMesh(Mesh);