# Set Static Mesh by UProperty Ref via Constructor (C++)

**URL:** <https://forums.unrealengine.com/t/set-static-mesh-by-uproperty-ref-via-constructor-c/2079530>\
**Category:** Programming & Scripting\
**Tags:** UProperty, constructors, unreal-engine, construction-script, question\
**Created:** [October 22, 2024, 2:52am UTC](https://forums.unrealengine.com/t/set-static-mesh-by-uproperty-ref-via-constructor-c/2079530 "2024-10-22T02:52:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LowResDev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LowResDev](https://forums.unrealengine.com/u/LowResDev)\
**Post date:** [October 22, 2024, 2:52am UTC](https://forums.unrealengine.com/t/set-static-mesh-by-uproperty-ref-via-constructor-c/2079530/1 "2024-10-22T02:52:59Z")

</div>

![huh1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/f/7/2f7206144ce5d042d7a4acfce96f41e7908c5599.png)

I would like to set the Static Mesh of a Static Mesh Component by referencing a UStaticMesh property via the constructor in C++. It works via BeginPlay, Tick, and the constructor via Blueprints, but not the constructor via C++.

The desired effect would be to select a static mesh for the UProperty and have that propagate to several Static Mesh Components on the actor while in the editor (before pressing play).

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [October 22, 2024, 7:12am UTC](https://forums.unrealengine.com/t/set-static-mesh-by-uproperty-ref-via-constructor-c/2079530/2 "2024-10-22T07:12:19Z")

</div>

Use PostEditChangeProperty.

header

```auto
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Engine/StaticMesh.h"
#include "PropagateActor.generated.h"

UCLASS()
class YOUR_API APropagateActor : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	APropagateActor();

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

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

	UPROPERTY(BlueprintReadWrite,EditAnywhere)
	UStaticMesh* TargetMesh;

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	UStaticMeshComponent* Mesh1;

	void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
	
};

```

cpp

```auto
#include "PropagateActor.h"

APropagateActor::APropagateActor()
{

	PrimaryActorTick.bCanEverTick = true;
	TargetMesh = CreateDefaultSubobject<UStaticMesh>(TEXT("StatMesh"));
	Mesh1 = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh1"));	
}

void APropagateActor::BeginPlay()
{
	Super::BeginPlay();	
}

void APropagateActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

void APropagateActor::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
	Super::PostEditChangeProperty(PropertyChangedEvent);	
	Mesh1->SetStaticMesh(TargetMesh);
	Mesh1->MarkRenderStateDirty();
}

```

---

<div class="post-metadata">

**Author:** ![LowResDev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LowResDev](https://forums.unrealengine.com/u/LowResDev)\
**Post date:** [October 22, 2024, 9:27pm UTC](https://forums.unrealengine.com/t/set-static-mesh-by-uproperty-ref-via-constructor-c/2079530/3 "2024-10-22T21:27:00Z")

</div>

Thank you very much. Just got the same answer on Reddit. Worked perfectly. I greatly appreciate the help \<3
