When you finish editing a level instance, the actor is converted from the world position to the local position of the level instance, but if you replace the actor, the conversion process is performed by retrieving the original (marked for deletion) actor from the package, not the new actor.

The following workaround that removes the old package from PackageMap works.

void UEditorEngine::ReplaceActors(UActorFactory* Factory, const FAssetData& AssetData, const TArray<AActor*>& ActorsToReplace)
		FActorSpawnParameters SpawnParams;
		SpawnParams.Name = OldActorName;
		SpawnParams.bCreateActorPackage = false;
		SpawnParams.OverridePackage = OldActor->GetExternalPackage();
		SpawnParams.OverrideActorGuid = OldActor->GetActorGuid();
		// Don't go through AActor::Rename here because we aren't changing outers (the actor's level) and we also don't want to reset loaders
		// if the actor is using an external package. We really just want to rename that actor out of the way so we can spawn the new one in
		// the exact same package, keeping the package name intact.
		OldActor->UObject::Rename(*OldActorReplacedNamed.ToString(), OldActor->GetOuter(), REN_DoNotDirty | REN_DontCreateRedirectors | REN_ForceNoResetLoaders);

		OldActor->SetExternalPackage(nullptr);	//workaround

		const FTransform OldTransform = OldActor->ActorToWorld();
		UE_LOG( LogTemp, Display, TEXT("%s %s"), *OldActor->GetName(), *OldTransform.ToString() );

Steps to Reproduce
  1. open attached repro project on ue5.0 [Link Removed]
  2. Select BPP_PLI_Cubes in world outliner and start editing level instance
  3. Select a cube in the level instance
  4. Click "Replace "Replace selected actors with..." > any actor in context menu on the cube
  5. Select BPP_PLI_Cubes in world outliner again and click "Commit Changes"  button in detail pane

see video  [Link Removed] for detail


The replaced actor moves to wrong location 




Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-159517 in the post.

Login to Vote

CreatedJul 14, 2022
UpdatedFeb 10, 2023