Download

Setting FActorSpawnParameters::Instigator has no effect

Could this be a bug ?

With a code like below


FActorSpawnParameters p;
p.bNoCollisionFail = true;
p.bNoFail = true;
p.Instigator = Controller->GetPawn();
ADerivedFromPawn* SomePawn = World->SpawnActor<ADerivedFromPawn>( ADerivedFromPawn::StaticClass, p );


Afterward, SomePawn->Instigator is always equal to SomePawn, not Controller->GetPawn()

After looking into the source code, the function APawn::PreInitializeComponents overwrite Instigator to this.
Totally ignoring the Instigator set earlier at AActor::PostSpawnInitialize.

That line of code has been that way literally since the unrealengine was put in to perforce in 2000. So not scary to change at all …

I think you’re right however, and after a quick discussion I’m going to change the PreInitializeComponents to only set Instigator = this if it is null, that way if it has been specified via the parameters that value will be sustained.