# How can I change actor's default properties on runtime with c++?

**URL:** <https://forums.unrealengine.com/t/how-can-i-change-actors-default-properties-on-runtime-with-c/409528>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [November 13, 2017, 7:56pm UTC](https://forums.unrealengine.com/t/how-can-i-change-actors-default-properties-on-runtime-with-c/409528 "2017-11-13T19:56:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![charliee88](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@charliee88](https://forums.unrealengine.com/u/charliee88)\
**Post date:** [November 13, 2017, 7:56pm UTC](https://forums.unrealengine.com/t/how-can-i-change-actors-default-properties-on-runtime-with-c/409528/1 "2017-11-13T19:56:50Z")

</div>

I’m trying to change actor’s default properties on runtime.  
I approach to the default properties using CDO and I changed them.  
But when I spawn the actor, the properties aren’t changed.  
Is there any way to change default properties on runtime?

---

<div class="post-metadata">

**Author:** ![Rogue\_Programmer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rogue_programmer/32/731748_2.png) [@Rogue\_Programmer](https://forums.unrealengine.com/u/Rogue_Programmer)\
**Post date:** [November 13, 2017, 9:20pm UTC](https://forums.unrealengine.com/t/how-can-i-change-actors-default-properties-on-runtime-with-c/409528/2 "2017-11-13T21:20:24Z")

</div>

I’m not sure exactly what you are trying to set, but you might want to try spawning deferred so you can change the class properties on the instanced actor itself. [UWorld::SpawnActorDeferred | Unreal Engine Documentation](https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Engine/UWorld/SpawnActorDeferred/)

---

<div class="post-metadata">

**Author:** ![charliee88](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@charliee88](https://forums.unrealengine.com/u/charliee88)\
**Post date:** [November 14, 2017, 9:08am UTC](https://forums.unrealengine.com/t/how-can-i-change-actors-default-properties-on-runtime-with-c/409528/3 "2017-11-14T09:08:34Z")

</div>

Thank you for the answer but I think it isn’t what I’m looking for.  
My explanation may not be enough.  
I’m trying to change actor’s variables which are declared by myself before spawn the actor.  
The variables include struct and array.  
I realize that “Default properties” may be an inappropriate expression for this situation.

---

<div class="post-metadata">

**Author:** ![Dune](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dune](https://forums.unrealengine.com/u/Dune)\
**Post date:** [November 14, 2017, 10:15am UTC](https://forums.unrealengine.com/t/how-can-i-change-actors-default-properties-on-runtime-with-c/409528/4 "2017-11-14T10:15:48Z")

</div>

The constructor for a code class is usually called when first spawned but also when open in the editor (I believe so that things changed there are also displayed in the editor). Although I’m not actually sure from your explanation what you are trying to achieve?

You can use the Defereed method, or simply create a function called Initialise on your class, and after spawning the actor, use this function to set any variables right away?

---

<div class="post-metadata">

**Author:** ![Unzkilled](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Unzkilled](https://forums.unrealengine.com/u/Unzkilled)\
**Post date:** [November 14, 2017, 10:33am UTC](https://forums.unrealengine.com/t/how-can-i-change-actors-default-properties-on-runtime-with-c/409528/5 "2017-11-14T10:33:43Z")

</div>

The constructor is used for the sake of construction of the object, before it be spawned or initialized. The function you are looking for is the BeginPlay, which is called in the moment the object comes into game. There is a limitation in the BeginPlay method where you can’t use it to find assets calling the ConstructorHelpers. If you need to build components, set materials and another stuff involving assets you will need to use the StaticLoadObject method.

More information on:

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

---

<div class="post-metadata">

**Author:** ![charliee88](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@charliee88](https://forums.unrealengine.com/u/charliee88)\
**Post date:** [November 14, 2017, 11:51am UTC](https://forums.unrealengine.com/t/how-can-i-change-actors-default-properties-on-runtime-with-c/409528/6 "2017-11-14T11:51:20Z")

</div>

I’m sorry. I didn’t mention that I want to set the variables from other class.  
I can set the variables just after spawning and it will show same result but I want to set the variables before spawning.  
I tried it using CDO but it didn’t work.

---

<div class="post-metadata">

**Author:** ![Nachtmahr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nachtmahr](https://forums.unrealengine.com/u/Nachtmahr)\
**Post date:** [November 14, 2017, 12:17pm UTC](https://forums.unrealengine.com/t/how-can-i-change-actors-default-properties-on-runtime-with-c/409528/7 "2017-11-14T12:17:39Z")

</div>

As AlfornoOne said use the Defered Spawn, set everything you need and call FinishSpawningActor afterwards. This will override any defaults of the CDO and runs the Construction Script afterwards (BP) and actually Spawns your Actor.

---

<div class="post-metadata">

**Author:** ![Unzkilled](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Unzkilled](https://forums.unrealengine.com/u/Unzkilled)\
**Post date:** [November 14, 2017, 12:44pm UTC](https://forums.unrealengine.com/t/how-can-i-change-actors-default-properties-on-runtime-with-c/409528/8 "2017-11-14T12:44:02Z")

</div>

What kind of variables are those? Can you give us the full sample?

---

<div class="post-metadata">

**Author:** ![charliee88](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@charliee88](https://forums.unrealengine.com/u/charliee88)\
**Post date:** [November 14, 2017, 10:07pm UTC](https://forums.unrealengine.com/t/how-can-i-change-actors-default-properties-on-runtime-with-c/409528/9 "2017-11-14T22:07:42Z")

</div>

It worked with Defered Spawn. I misunderstood about Defered Spawn so I thought it wasn’t the solution. Thank you all.
