Component Collision Problem

I have a problem getting collisions of components to work in C++.
My goal is a subclass of the UStaticMeshComponent that checks for collision with other Actor’s Collision components.
I have the following constructor:

UWeaponComponent::UWeaponComponent(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
	static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMeshOb_torus(TEXT("StaticMesh'/Game/TopDown/Meshes/CubeMesh.CubeMesh'"));
	if (StaticMeshOb_torus.Object)
		SetStaticMesh(StaticMeshOb_torus.Object);

	bGenerateOverlapEvents = true;
	OnComponentBeginOverlap.AddDynamic(this, &UWeaponComponent::OnBeginOverlap);
	SetCollisionResponseToChannel(ECollisionChannel::ECC_GameTraceChannel1, ECollisionResponse::ECR_Overlap);
	SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
	SetCollisionObjectType(ECC_GameTraceChannel1);
}

and the following OnBeginOverlap method:

void UWeaponComponent::OnBeginOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool x, const FHitResult& hit)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, "Hit !!!");
}

My problem is: the OnBeginOverlap method is never executed. I don’t think there is a problem with the collision channels because I can simply add the OnComponentBeginOverlap event for this component in the blueprint and it works without any any changes in the collision settings.

Here is my collision component constructor (for completeness):

UHitDetectionComponent::UHitDetectionComponent(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
	OnComponentBeginOverlap.AddDynamic(this, &UHitDetectionComponent::OnBeginOverlap);
	SetCollisionResponseToChannel(ECollisionChannel::ECC_GameTraceChannel1, ECollisionResponse::ECR_Overlap);
	bGenerateOverlapEvents = true;
	SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
	SetCollisionObjectType(ECC_GameTraceChannel1);
}

Am I missing something?

I am even more confused because the HitDetectionComponents work as intended. If two characters with these components collide the corresponding C++ method OnBeginOverlap is called.

I seem to be having a similar issue when following the FPS Tutorial. After turning on simulated physics for the static mesh cube, my projectiles still pass through it.

No ideas? (bump)

Maybe you want to try to set it to a preset instead of selection properties yourself? Just a test anyway :

test->SetCollisionProfileName(TEXT("Trigger"));

You can replace Trigger by another preset, but Trigger should definetly make the call to OnComponentBeginOverlap.

Also make sure that the component you are setting collision on as a collision geometry in it’s static mesh or skeletal mesh (if they are what you are using as collision) or that you are using a BoxComponent, SphereComponent or CapsuleComponent.

Another reason could be because you think a component should be your collision but your actor is using another component as the collision component and thus, it is not working out.

Hope this helps…

Thank you for the response,
I tried your suggestion but it did not work. Also the collision does work when implemented with Blueprints. So I assume that the collision geometry and channels are working correctly.

I am not sure I understand what you wrote in your last paragraph. Can an actor somehow block all further collision of components? Or did I misunderstand you?

I would have to validate that, but if you have a component with a collision that is child of a component with different collision presets, I think it could overwrite the child collision settings. Again, I’m not sure of that so, just a suggestion…

I will look into that.

I did a quick test by looking at the collision settings of the component at runtime and everything looks fine.
It would be pretty mean if the settings would get overridden without showing the changes in the component’s property window.

Still no luck. I am running out of things to try.