How set component in cpp with value from derived BP class?

Hi.

I created cpp Actor class and derived BP class from it.

I want to set UStaticMesh in BP and manage SetStaticMesh logic in BP. Nothing I tried leaded to result I would like.

header:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Projectile)
class UStaticMeshComponent* ComponentCoreMesh;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Projectile)
UStaticMesh* CoreMesh;

constructor:

ComponentCoreMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("CoreMesh"));
ComponentCoreMesh->SetStaticMesh(CoreMesh);
ComponentCoreMesh->SetupAttachment(RootComponent);

What I expect: After I set UStaticMesh to UStaticMeshComponent in constructor I would see my change in Viewport.

What I got: Viewport shows no change. But after spawn it works fine.

And since UStaticMeshComponent is inherited, I can’t use transform. So is there a way to change inherited values in BP? ( by some UPROPERTY property ? )

And mainly, is there a way to call constructor in cpp to see result in BP Viewport ?

Thanks a lot.

You need to know when “CoreMesh” has changed so you can call “ComponentCoreMesh->SetStaticMesh(CoreMesh)” again. You can override the UObjects “PostEditChangeProperty” for this. Its very simple if you know what you are looking for.

This answer may help you:

Thanks, thats it.