Prefab Tool - Prefab Support for Unreal Engine

@,

I dug around a bit in the code and I think I may have found the problem. I’m not very knowledgeable about this stuff in Unreal , so I might be off base.

The intent of RevertPrefabActor is to replace an existing prefab actor’s hierarchy with the one defined in the asset. To do this, it collects a bunch of information about the particular instance and then calls SpawnPrefabInstances to get a new hierarchy to replace the old one. Eventually, ReplacePrefabInstances is called to rename the new actors to their original names. Although the rename code here looks good, somehow a name conflict happens and it crashes.

Although the rename code in ReplacePrefabInstances looks clean, it still dies when using multiple sublevels. When debugging, I noticed that the new actors weren’t in the expected level. They were in the base map, not the sub level.

So, I went to look at how they were spawned. SpawnPrefabInstances calls edactPastSelected, which pastes the new actors into the World’s current level. So, I decided to set the World’s current level before calling SpawnPrefabInstances. Here is my hack/fix:

at approximately PrefabToolHelpers.cpp:1804



			// Spawn prefab instances
			TArray<AActor*> SpawnInstances;
			TArray<AGroupActor*> NewGroupActors;
			PrefabActor->GetLevel()->OwningWorld->SetCurrentLevel(PrefabActor->GetLevel());
			SpawnPrefabInstances(Prefab, PrefabActor->GetLevel()->OwningWorld, SpawnInstances, &NewGroupActors);
			PostSpawnPrefabInstances(Prefab, SpawnInstances, PrefabActor, &NewGroupActors);


This seems to keep the crash from happening. Previously, the new objects were all going into the base map but I think MakeUniqueObjectName makes a unique name in the outer of the old actor. But the place we’re pasting into isn’t in that context. So we can step on our own toes. This poited out that those actors might not have been created in the right level anyway. So, by fixing the level they are spawned in, it fixes the problem.

At least that’s the theory. :slight_smile: Let me know if there’s a more appropriate fix or if I’m just off-base.

Cheers,
poz