Hello,
I’m using procedural mesh to get overlapping actor of custom shapes. As I’m quite new to procedural meshes, I might have done something wrong. The problem is that my procedural mesh does not detect collisions, if I move it into my enemies (in unpossesed mode), but if I move an enemy into my procedural mesh, it detects the collision.
Here is the code of my procedural mesh :
ACone::ACone()
{
mesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("GeneratedMesh"));
RootComponent = mesh;
precalcPoints = TArray<FVector>();
for (int i = 0;i<360; i+=10)
{
precalcPoints.Add(FVector(FMath::Cos(FMath::DegreesToRadians(i)), FMath::Sin(FMath::DegreesToRadians(i)) , 0.0f));
}
// New in UE 4.17, multi-threaded PhysX cooking.
mesh->bUseAsyncCooking = true;
mesh->SetMobility(EComponentMobility::Movable);
mesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
mesh->SetCollisionProfileName("OverlapAll");
mesh->OnComponentBeginOverlap.AddDynamic(this, &ACone::OnPickup);
SetActorEnableCollision(true);
}
void ACone::CreateCone()
{
float angleInRad = FMath::DegreesToRadians(_angle / 2.0f);
TArray<FVector> vertices;
vertices.Add(FVector(0, 0, 0));//start
float _currentAngle = -_angle / 2.0f;
vertices.Add(FVector(FMath::Cos(-angleInRad), FMath::Sin(-angleInRad), 0)*_length);
_currentAngle -= (int)_currentAngle % 10;
for (int i = _currentAngle; i < _angle / 2.0f; i += 10)
{
int index = i / 10;
if (index < 0)
{
index = index % 36;
index += 36;
}
else
{
index = index % 36;
}
vertices.Add(precalcPoints[index] * _length);
}
if (_currentAngle != _angle / 2.0f)
vertices.Add(FVector(FMath::Cos(angleInRad), FMath::Sin(angleInRad), 0)*_length);
TArray<int32> Triangles;
for (int i = 0; i < vertices.Num() - 1; i++)
{
Triangles.Add(0);
Triangles.Add(i + 2);
Triangles.Add(i + 1);
}
mesh->CreateMeshSection_LinearColor(0, vertices, Triangles, {}, {}, {}, {}, true);
// Enable collision data
mesh->ContainsPhysicsTriMeshData(true);
}