# Attach StaticMesh to Actor?

**URL:** <https://forums.unrealengine.com/t/attach-staticmesh-to-actor/37833>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [August 7, 2015, 10:45am UTC](https://forums.unrealengine.com/t/attach-staticmesh-to-actor/37833 "2015-08-07T10:45:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_a04a0eae1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a04a0eae1](https://forums.unrealengine.com/u/anonymous_user_a04a0eae1)\
**Post date:** [August 7, 2015, 10:45am UTC](https://forums.unrealengine.com/t/attach-staticmesh-to-actor/37833/1 "2015-08-07T10:45:03Z")

</div>

This should be simple but none of the tutorials on the Wiki did quite what I want…

I have a subclass of Actor, and I want to have a property that lets designers choose a StaticMesh to be displayed.

```auto

UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = "Vehicle Part Properties")
UStaticMesh * StaticMeshAsset;

```

Also going to need a StaticMeshComponent…

```auto

UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Mesh")
UStaticMeshComponent * StaticMesh;

```

All I want to do is attach the StaticMesh to the Actor on creation.

```auto

AVehiclePart::AVehiclePart()
{
 	// 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;

	// Attach a scene componet to root
	USceneComponent * SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root Component"));
	RootComponent = SceneComponent;

	StaticMesh->SetStaticMesh(StaticMeshAsset);

	// Attach the specified static mesh to the scene component
	StaticMesh->AttachTo(RootComponent);

}

```

This blows up UE4. Trying to adapt [this tutorial](https://docs.unrealengine.com/latest/INT/Programming/Tutorials/Components/1/index.html). Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Mhousse1247](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mhousse1247](https://forums.unrealengine.com/u/Mhousse1247)\
**Post date:** [August 7, 2015, 11:08am UTC](https://forums.unrealengine.com/t/attach-staticmesh-to-actor/37833/2 "2015-08-07T11:08:00Z")

</div>

You can use OnConstruction , and set your SM there

```auto

virtual void OnConstruction(const FTransform& Transform) override

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a04a0eae1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a04a0eae1](https://forums.unrealengine.com/u/anonymous_user_a04a0eae1)\
**Post date:** [August 7, 2015, 2:42pm UTC](https://forums.unrealengine.com/t/attach-staticmesh-to-actor/37833/3 "2015-08-07T14:42:43Z")

</div>

AH perfect, thanks!
