# How do you add components to an actor class at runtime in C++?

**URL:** <https://forums.unrealengine.com/t/how-do-you-add-components-to-an-actor-class-at-runtime-in-c/277796>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [March 22, 2014, 12:04am UTC](https://forums.unrealengine.com/t/how-do-you-add-components-to-an-actor-class-at-runtime-in-c/277796 "2014-03-22T00:04:51Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 25, 2014, 10:54pm UTC](https://forums.unrealengine.com/t/how-do-you-add-components-to-an-actor-class-at-runtime-in-c/277796/5 "2014-03-25T22:54:30Z")

</div>

#Attach

What you CAN easily do

is spawn Static Mesh Actors

and Attach them to your core ship component that is always created.

Then you can go wild with creating Static Mesh assets and then you can dynamically set the Static Mesh Actor’s Static mesh in code

#Set Static Mesh

//AStaticMeshActor\* MySMA in .h  
if(!MySMA) return;  
MySMA-\>StaticMeshComponent-\>SetStaticMesh(your static mesh)

#Dynamic Load Object

See my wiki page to load your various static mesh assets from file path

> **[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...

---

_[View the full topic](https://forums.unrealengine.com/t/how-do-you-add-components-to-an-actor-class-at-runtime-in-c/277796)._
