What I’m trying to create is an obstacle that the player will pass through, but get damaged when he does (think of crashing head first into some glass). I have added a new collision profile for it in DefaultEngine.ini like this:
[/Script/Engine.CollisionProfile]
+Profiles=(Name="ObstacleMesh",CollisionEnabled=QueryAndPhysics,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that overlaps Pawn, Camera, and Vehicle. All other channels will be set to default. ",bCanModify=False)
My obstacle class is set up like this:
UCLASS()
class AObstacle : public AActor
{
GENERATED_UCLASS_BODY()
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Mesh)
TSubobjectPtr<UStaticMeshComponent> OriginalMesh;
UFUNCTION()
void OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
};
And the definitions are:
AObstacle ::AObstacle(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
OriginalMesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, "OriginalMesh");
OriginalMesh->BodyInstance.SetInstanceSimulatePhysics(false);
OriginalMesh->SetCollisionProfileName(TEXT("ObstacleMesh"));
OriginalMesh->OnComponentBeginOverlap.AddDynamic(this, &AObstacle::OnOverlap);
RootComponent = OriginalMesh;
}
void AObstacle::OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, "Overlapped in C++");
}
But the event won’t fire when the pawn enters the mesh. I tried adding the overlap event in the Blueprint subclass I’m placing in the scene, and it fires there, which means the problem is probably not with the setup of collision profiles and channels, but not in C++. Any ideas why this is happening?