# Loading static meshes during runtime?

**URL:** <https://forums.unrealengine.com/t/loading-static-meshes-during-runtime/287772>\
**Category:** Asset Creation\
**Tags:** unreal-engine, editor, staticmesh, CPP, question\
**Created:** [July 9, 2014, 6:43pm UTC](https://forums.unrealengine.com/t/loading-static-meshes-during-runtime/287772 "2014-07-09T18:43:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lordink](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lordink](https://forums.unrealengine.com/u/Lordink)\
**Post date:** [July 9, 2014, 6:43pm UTC](https://forums.unrealengine.com/t/loading-static-meshes-during-runtime/287772/1 "2014-07-09T18:43:10Z")

</div>

Hi guys,

I am interested in assigning static mesh to my static mesh component during runtime, after I receive a string with path to specific mesh from other class. So, in constructor, I just do

```
Mesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PickupMesh1P"));
RootComponent = Mesh;
...

```

then, in the other member function of the class, when I get the FString with correct mesh path (e.g. _“StaticMesh’/Game/Shapes/Shape\_Pipe\_180.Shape\_Pipe\_180’”_), I would like to assign that mesh to my component. The only way I know is this:

```
FString mpath = Item ->getMeshInfo();
static ConstructorHelpers::FObjectFinder<UStaticMesh> PickupMesh(*mpath);
Mesh->SetStaticMesh(PickupMesh.Object);

```

which obviously does not work, as ConstructorHelpers::FObjectFinder can only be used in constructor.

How do I do that in the right way? I do not believe that there is no way to dynamically alter static mesh models during runtime.

---

<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:** [July 9, 2014, 7:08pm UTC](https://forums.unrealengine.com/t/loading-static-meshes-during-runtime/287772/2 "2014-07-09T19:08:48Z")

</div>

#Dynamic Load Object

I have an in-game editor where I get and set static mesh assets all the time!

Here’s how I do it

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

please note

If you have a lot of mesh assets to reference that you know before compile time, you should stick them in a .h somewhere like this

```
UPROPERTY(EditDefaultsOnly,BlueprintReadOnly,Category="SM Assets")
UStaticMesh* MySmAsset1;

UPROPERTY(EditDefaultsOnly,BlueprintReadOnly,Category="SM Assets")
UStaticMesh* MySmAsset2;

UPROPERTY(EditDefaultsOnly,BlueprintReadOnly,Category="SM Assets")
UStaticMesh* MySmAsset3;

```

And then use SetStaticMesh directly with that

Reason: During packaging the above references will be carried over correctly.

Reason2: They’re super easy to change at any time without requiring code compile.

Hardcoding asset paths is bad idea cause they will change during packaging and may not get updated.

My Dynamic Load Object is for when you dont know which mesh to load pre-compile time, but the user picks one in game / you maybe randomly choose from a series of meshes

#Video

Here’s a video of my runtime use case!

In the very beginning, I am clicking on different mesh and using my Dynamic Load Object code above to get the mesh asset to build with

🙂

Rama

---

<div class="post-metadata">

**Author:** ![Lordink](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lordink](https://forums.unrealengine.com/u/Lordink)\
**Post date:** [July 9, 2014, 7:32pm UTC](https://forums.unrealengine.com/t/loading-static-meshes-during-runtime/287772/3 "2014-07-09T19:32:14Z")

</div>

Thanks, man, that works now. However, while in “Simulation” mode I clearly see my mesh, for some reason if I start playing as a player I don’t see it on the map. Do u have any thoughts, why does that happen?  
I have flags set in a right way, as far as I understand:

```
Mesh->SetVisibility(true);
	Mesh->bOnlyOwnerSee = false;
	Mesh->bCastDynamicShadow = false;
	Mesh->bCastStaticShadow = false;
	Mesh->bReceivesDecals = false;
```

---

<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:** [July 9, 2014, 10:30pm UTC](https://forums.unrealengine.com/t/loading-static-meshes-during-runtime/287772/4 "2014-07-09T22:30:55Z")

</div>

#SetMobility(EComponentMobility::Movable)

Are you sure you set the mesh to be **moveable**

#you can’t change the meshes of static mobility meshes at run time

![9957-mobilitymoveable.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/7/1/c71dc0f931062410970abc976a95440be1af7ba0.jpeg)

🙂

#CPP Setting in Constructor

```
//Mobility
StaticMeshComponent->SetMobility(EComponentMobility::Movable);

```

or in your case

```
//Mobility
Mesh->SetMobility(EComponentMobility::Movable);

```

Rama

---

<div class="post-metadata">

**Author:** ![ANLevant](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ANLevant](https://forums.unrealengine.com/u/ANLevant)\
**Post date:** [August 28, 2020, 5:36pm UTC](https://forums.unrealengine.com/t/loading-static-meshes-during-runtime/287772/5 "2020-08-28T17:36:29Z")

</div>

Dude! fifth time today I come under the same wiki file that doesn’t exist anymore, and the video doesnt’even share source code
