Skip to content

Commit

Permalink
Disables the serialization of RelativeLocation for root components as…
Browse files Browse the repository at this point in the history
… it was causing problems with PhysicX when spawning multiple prefabs at Runtime.
  • Loading branch information
OmikronX committed Feb 8, 2020
1 parent 53678b5 commit e435145
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Source/PrefabricatorRuntime/Private/Prefab/PrefabTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,22 @@ namespace {
}
}

// JB: We skip serialization of RelativeLocation for root components.
// JB: The root component relative location is redundant as it equals to the actor location.
// JB: Having it set during deserialization causes problems with PhysicX when a large number of prefabs are spawned at runtime.
// 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.
// JB: In such a case, the physics has to deal with the overlaps (or at least I think so) and significantly slows down.
// JB: Especially if the assets have a large number of collisions.
USceneComponent* SceneComponent = Cast<USceneComponent>(ObjToSerialize);
if(SceneComponent && Cast<UPrefabComponent>(SceneComponent->GetAttachParent()))
{
if (Property->GetName().Equals("RelativeLocation"))
{
return true;
}
}


return false;
}

Expand Down Expand Up @@ -679,7 +695,8 @@ void FPrefabTools::LoadStateFromPrefabAsset(APrefabActor* PrefabActor, const FPr
}
}

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

0 comments on commit e435145

Please sign in to comment.