Actors spawned in editor do not run their construction scripts

Hello,

I have a custom details panel that I’ve added to an actor with a button. On the press of that button, I’m attempting to spawn other actors into the level. They spawn just fine, but the problem is they do not run their construction script until I either manually move them or modify a value on them in the editor.

I’ve tried spawning them with GEditor->AddActor(), GetWorld()->SpawnActor(), GetWorld->SpawnDeferredActor() and then calling FinishSpawning(), nothing will make it fire it’s constructor when it’s placed.

I’ve also tried programatically modifying a property or moving the actor immediately after spawning it. The values change on the blueprint, but it still doesn’t construct.

I’ve tried adding a BlueprintImplementableEvent and implementing it in the blueprint and calling it from C++, but even though there are no errors it doesn’t seem to get called at all.

I’ve completely run out of ideas here, so any help would be appreciated. :slight_smile:

Hey sbounds,

I’ve attempted to reproduce the issue you’re describing, but I’m not able to see the same results.

Here’s how I’m spawning my actor (which is called PickupActor in my ) on Begin Play:

FActorSpawnParameters SpawnParams;

UWorld* World = GetWorld();

World->SpawnActor<APickupActor>(SpawnParams);

Then in the Pickup Actor’s constructor, I’m printing a message

UE_LOG(LogTemp, Warning, (TEXT("Pickup Was Spawned")));

When I play, the actor is being spawned and the Pickup Was Spawned message is being added to the log as expected.

Could you provide the full code that you’re using to spawn your actor?

Hi ,

Thanks for the reply.

The problem is this is an editor tool so it needs to happen in editor time, not during runtime. I’m using the following code to add the actor to the level in the editor:

GEditor->AddActor(GEditor->LevelViewportClients[0]->GetWorld()->GetCurrentLevel(), AMyActor, MyTransform);

The actor gets placed just fine, but the constructor never fires in the editor. I’d expect it to fire the same as if I had manually drug an actor from the content browser into the viewport.

Edit:
Just to add a bit more after trying some things. The C++ constructor does fire, but the blueprint’s does not. I tried calling a blueprint implemented function from the C++ constructor as a workaround, but it doesn’t seem to get there.

I finally figured out how to get the results I wanted. When using GEditor->AddActor() to place an actor, it does run the construction scripts in the editor, not sure why I thought it wasn’t. But I also needed to modify some properties on the actor and then re-run the construction script, and finally found the function call I needed to do that:

AActor* newActor = GEditor->AddActor(GEditor->LevelViewportClients[0]->GetWorld()->GetCurrentLevel(), AMyActor, MyTransform);

// modify properties on newActor

newActor->RerunConstructionScripts();