C++ SpawnActor without the default contructor

Hi, I think I need help…

I’m currently working on something and I’d like to spawn a custom actor into the scene. More precisely, I have stored several staticmesh in an array and I tell which mesh to use when creating the object by giving a parameter in the constructor.
It works fine without the spawning part … but I’m kinda stuck when it comes to spawning it into the scene. I wanted to use the SpawnActor function but this one uses the default constructor while i’d like to specify some parameters before spawning.

Is it possible ?

I think you can’t do that. The best way is to have an Init function which take the parameters you need. You can call it just after spawn your actor. If you need to set something as a Owner or Instigator (responsible for damage) you can do it by using FActorSpawnParameters SpawnInfo. It is usefull if your actor enter in collision/overlap at spawn.

oh bummer… thanks for the quick answer.

I’m gonna try to spawn my object empty first and then set the mesh after in this case… which kinda sucks because ConstructorHelpers::FObjectFinder doesn’t work outsite constructor. I’ll find a workaround.

You can always use StaticLoadObject() outside of the constructor. E.g.

FString meshActorPath = TEXT("Path to your asset");

AStaticMeshActor* s = Cast<AStaticMeshActor>(StaticLoadObject(AStaticMeshActor::StaticClass(), NULL, *meshActorPath));

Thanks for taking the time to answer. I had started to do that actually. I wrapped it all in a static class to use it as a tool for my loads outside constructors.