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

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?

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

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.

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:

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?

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.

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.

1 Like

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

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

1 Like