Skip to content

Commit e435145

Browse files
committed
Disables the serialization of RelativeLocation for root components as it was causing problems with PhysicX when spawning multiple prefabs at Runtime.
1 parent 53678b5 commit e435145

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Source/PrefabricatorRuntime/Private/Prefab/PrefabTools.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,22 @@ namespace {
298298
}
299299
}
300300

301+
// JB: We skip serialization of RelativeLocation for root components.
302+
// JB: The root component relative location is redundant as it equals to the actor location.
303+
// JB: Having it set during deserialization causes problems with PhysicX when a large number of prefabs are spawned at runtime.
304+
// JB: Restoring the relative location will essentially put all spawned actors on top of each other even if the prefabs are spawned at different places.
305+
// JB: In such a case, the physics has to deal with the overlaps (or at least I think so) and significantly slows down.
306+
// JB: Especially if the assets have a large number of collisions.
307+
USceneComponent* SceneComponent = Cast<USceneComponent>(ObjToSerialize);
308+
if(SceneComponent && Cast<UPrefabComponent>(SceneComponent->GetAttachParent()))
309+
{
310+
if (Property->GetName().Equals("RelativeLocation"))
311+
{
312+
return true;
313+
}
314+
}
315+
316+
301317
return false;
302318
}
303319

@@ -679,7 +695,8 @@ void FPrefabTools::LoadStateFromPrefabAsset(APrefabActor* PrefabActor, const FPr
679695
}
680696
}
681697

682-
ChildActor = Service->SpawnActor(ActorClass, FTransform::Identity, PrefabActor->GetLevel(), Template);
698+
//JB: Spawning actors on top of each other may cause problems with PhysicX (as it needs to compute the overlaps).
699+
ChildActor = Service->SpawnActor(ActorClass, PrefabActor->GetActorTransform(), PrefabActor->GetLevel(), Template);
683700
if (!Template) {
684701
LoadActorState(ChildActor, ActorItemData, InSettings);
685702
if (InState.IsValid()) {

0 commit comments

Comments
 (0)