# Expose a Static Mesh Component from Code

**URL:** <https://forums.unrealengine.com/t/expose-a-static-mesh-component-from-code/54210>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [February 1, 2016, 10:56pm UTC](https://forums.unrealengine.com/t/expose-a-static-mesh-component-from-code/54210 "2016-02-01T22:56:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kanc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kanc](https://forums.unrealengine.com/u/Kanc)\
**Post date:** [February 1, 2016, 10:56pm UTC](https://forums.unrealengine.com/t/expose-a-static-mesh-component-from-code/54210/1 "2016-02-01T22:56:02Z")

</div>

Hi,

I have created a class and I want to have a reference to a non-existent static mesh component. I mean… I create a blueprint from my c++ class and then I create a static mesh component in viewport. I want to reference this new static mesh component from code.

I have tried with:

```auto

protected:
	UPROPERTY(EditAnywhere)
	UStaticMeshComponent* MeshCmpRef;

and

	UPROPERTY(VisibleDefaultsOnly)
	UStaticMeshComponent* MeshCmpRef;

```

But I dont see the exposed variable. Where is the issue??

Thanks!!

---

<div class="post-metadata">

**Author:** ![Jackblue](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jackblue/32/88706_2.png) [@Jackblue](https://forums.unrealengine.com/u/Jackblue)\
**Post date:** [February 2, 2016, 8:49am UTC](https://forums.unrealengine.com/t/expose-a-static-mesh-component-from-code/54210/2 "2016-02-02T08:49:27Z")

</div>

You simply need to initialize your component in your actor constructor and attach it to root.  
In this tutorial, he made it for a camera but, it’s exactly the same idea:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

I hope this help you 🙂

---

<div class="post-metadata">

**Author:** ![Kanc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kanc](https://forums.unrealengine.com/u/Kanc)\
**Post date:** [February 2, 2016, 7:45pm UTC](https://forums.unrealengine.com/t/expose-a-static-mesh-component-from-code/54210/3 "2016-02-02T19:45:36Z")

</div>

Thanks JackBlue!

I think that is not that i’m looking for… it’s hard to explain.

I want the static mesh component will be created from the blueprint, just using “Add Component-\>static mesh component” in the viewport. Then I want to have an exposed static mesh component pointer (null by default) and point to the static mesh component that I have created previously in the viewport.

I mean that all the CreateDefaultSubobject\<…\> stuff will be managed internal by the engine not in my code.

it’s difficult to explain in english for me… sorry.

Thanks again!
