Hi, I’m using 4.27 Chaos.
I’ve created a GeometryCollection in editor and I want to spawn it into my game at runtime via c++.
I’ve added a GeometryCollectionComponent to my actor and called SetRestCollection on it and passed the GeometryCollection. This seems to work and I do see the GeometryCollection mesh in the game. The issue is that it just hangs in the air and has no collisions. I expect it to fall to the ground and for it to collide with the player and the static mesh floor. This happens even if I enable gravity on the component and set its collision responses and channel. I also tried to break it via ApplyKinematicField(), but yeah, it doesn’t do anything either. If I call SetSimulatePhysics(true) on it, it just crashes.
I’ve tried a ton of different API calls and looked at the engine sources to see if I missed something, but nothing seems to work. It seems to be a more fundamental issue. The GeometryCollection is very simple. It’s based on a 2 triangle plane that I use everywhere in the game. It only has two pieces when fractured. All I did was create it, fracture it in the fracture editor, save it and load it at runtime.
Here’s a look at what the code looks like:
// In constructor
m_geometryCollectionComponent = CreateDefaultSubobject<UGeometryCollectionComponent>(STR_NAME_DESTRUCTIBLE_COMPONENT);
...
// At some point later during runtime.
if (m_geometryCollectionComponent)
{
UGeometryCollection* coll = (UGeometryCollection*)StaticLoadObject(UGeometryCollection::StaticClass(), NULL, TEXT("GeometryCollection'/Game/FirstPerson/Meshes/Plan/Shape_Plane_GeometryCollection_Top.Shape_Plane_GeometryCollection_Top'"));
if (coll)
{
m_geometryCollectionComponent->SetMaterial(0, material);
m_geometryCollectionComponent->SetWorldLocationAndRotation(actorLocation, meshRotation);
m_geometryCollectionComponent->SetRelativeScale3D(meshScale);
m_geometryCollectionComponent->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECR_Ignore);
m_geometryCollectionComponent->SetCollisionResponseToChannel(ECollisionChannel::ECC_WorldDynamic, ECR_Ignore);
m_geometryCollectionComponent->SetCollisionObjectType(ECollisionChannel::ECC_Destructible);
m_geometryCollectionComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
m_geometryCollectionComponent->SetRestCollection(coll);
m_geometryCollectionComponent->SetEnableGravity(true);
//m_geometryCollectionComponent->SetSimulatePhysics(true);
m_geometryCollectionComponent->SetCollisionResponseToChannel(ECollisionChannel::ECC_WorldStatic, ECR_Block);
m_geometryCollectionComponent->ApplyKinematicField(1000.0f, actorLocation);
}
}