Instanced static mesh does not trigger collisions

Hi,

I’ve made a simple level generator using Instanced Mesh Components. Everything was working great, but I’ve decided to split the map into smaller chunks. I moved the required components to a new Actor class and spawn a grid of chunks and instantiate meshes in them. After that, the collisions stopped working and the character just drops through it into the abyss. What could be the issue here? The physics and collision settings on the components are exactly the same. All that’s different is that instances are added to actors spawning at runtime instead of one being there from the start. Does that make any difference?

Here’s the chunk’s constructor

AMapChunk::AMapChunk()
{ 
StaticMeshComponent = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("FloorMesh"));
StaticMeshComponent->RegisterComponent();
StaticMeshComponent->ReleasePerInstanceRenderData();
StaticMeshComponent->InitPerInstanceRenderData(true);
StaticMeshComponent->SetFlags(RF_Transactional);
AddInstanceComponent(StaticMeshComponent);

RootComponent = StaticMeshComponent;
}

Any ideas? Does the component need the collisions to be initialized manually since it’s spawned and used during beginplay?


UPDATE:

Oddly enough, after switching transform’s mobility in editor DURING runtime the collisions seem to work again. I’m going to look into that…

Here is my setup:

    StaticMeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
	StaticMeshComponent->SetNotifyRigidBodyCollision(true);
	StaticMeshComponent->SetSimulatePhysics(true);

    // This part is optional
	StaticMeshComponent->SetLinearDamping(.3f);
	StaticMeshComponent->SetAngularDamping(.3f);

Hi,

I have tried your solution, but the issue still remains. If I place a chunk on the map in editor it works properly, but not when it’s spawned during runtime. I wonder if there is a method that doesn’t get called because of that…

So I have found a workaround for the issue. Like i mentioned in the update changing component transform’s mobility fixes the issue. What I do is set the mobility on BeginPlay and change the default one in the blueprint to something else, so it gets updated on runtime, which makes it work, but I’m sure there has to be a way to do it properly.