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() );
see video [Link Removed] for detail
Result:
The replaced actor moves to wrong location
There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-159517 in the post.
0 |
Component | UE - World Creation - Worldbuilding Tools - Level Instances |
---|---|
Affects Versions | 5.0.2 |
Target Fix | 5.3 |
Created | Jul 14, 2022 |
---|---|
Resolved | May 1, 2023 |
Updated | May 1, 2023 |