# Runtime generation of actors

**URL:** <https://forums.unrealengine.com/t/runtime-generation-of-actors/343285>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [January 6, 2016, 4:45pm UTC](https://forums.unrealengine.com/t/runtime-generation-of-actors/343285 "2016-01-06T16:45:00Z")\
**Posts on this page:** 6\
**Page:** 3

<div class="post-metadata">

**Author:** ![CJSTRAW93](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CJSTRAW93](https://forums.unrealengine.com/u/CJSTRAW93)\
**Post date:** [February 8, 2016, 1:06am UTC](https://forums.unrealengine.com/t/runtime-generation-of-actors/343285/41 "2016-02-08T01:06:01Z")

</div>

I’ll try that and see what happens. I’ve attached a text file to my code, it’s easier than copy and pasting it and it take up endless sections on this page.link text

---

<div class="post-metadata">

**Author:** ![CJSTRAW93](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CJSTRAW93](https://forums.unrealengine.com/u/CJSTRAW93)\
**Post date:** [February 9, 2016, 5:36pm UTC](https://forums.unrealengine.com/t/runtime-generation-of-actors/343285/42 "2016-02-09T17:36:31Z")

</div>

I’ve added a breakpoint to the code and found that when I get past this line: `NewCube->GetStaticMeshComponent()->SetStaticMesh(MyCubeMesh);`

it says this in the locals tab in Visual studio next to my NewCube value: ‘variable is optimized away and not available’. I think this may be the problem, but I don’t have a solution to it. I tried changing it volatile as per a website I found, but no luck.

---

<div class="post-metadata">

**Author:** ![CJSTRAW93](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CJSTRAW93](https://forums.unrealengine.com/u/CJSTRAW93)\
**Post date:** [February 16, 2016, 3:25pm UTC](https://forums.unrealengine.com/t/runtime-generation-of-actors/343285/43 "2016-02-16T15:25:02Z")

</div>

Hey TTaM, I’ve implemented your code and it almost works. Literally a fraction away. I don’t know if you’ve seen it below but the actor appears in the world outliner but there is no mesh so it is invisible, until i assign it one in the editor while the program runs. Any suggestions? 🙂

---

<div class="post-metadata">

**Author:** ![Daekesh](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/daekesh/32/918652_2.png) [@Daekesh](https://forums.unrealengine.com/u/Daekesh)\
**Post date:** [February 16, 2016, 3:53pm UTC](https://forums.unrealengine.com/t/runtime-generation-of-actors/343285/44 "2016-02-16T15:53:26Z")

</div>

I’d add a break point to your constructor to see if the MyCubeMesh variable is being assigned properly.

---

<div class="post-metadata">

**Author:** ![CJSTRAW93](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CJSTRAW93](https://forums.unrealengine.com/u/CJSTRAW93)\
**Post date:** [February 16, 2016, 9:48pm UTC](https://forums.unrealengine.com/t/runtime-generation-of-actors/343285/45 "2016-02-16T21:48:13Z")

</div>

Here’s what the locals show after adding a breakpoint to my code. There is something assigned to MyCubeMesh, however with me being new to unreal I’m not sure if it’s anywhere near right. Any chance you can enlighten me on this?

 ![78789-runtime_gen+locals.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/8/a/58ae263c5e6e6f82bcfe6c31feaeb068e8c01de5.png)

---

<div class="post-metadata">

**Author:** ![CJSTRAW93](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CJSTRAW93](https://forums.unrealengine.com/u/CJSTRAW93)\
**Post date:** [February 20, 2016, 8:38pm UTC](https://forums.unrealengine.com/t/runtime-generation-of-actors/343285/46 "2016-02-20T20:38:16Z")

</div>

Ok so i put a breakpoint in the code to find out what’s going on. I found that the AStaticMeshActor\* variable NewCube has a different assigned value to the MyCubeMesh variable. I’m not sure how but at some point the variable is being changed or isn’t being assigned correctly in the first place. Is there any chance you could test this for me because this is probably the solution?

 ![79238-runtime+gen+log.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/9/1/c91c3932dab6d7217d990b2466bc750ea72fac29.png)

[Previous page](https://forums.unrealengine.com/t/runtime-generation-of-actors/343285.md?page=2)
