Do OnComponentOverlap Events work with static meshes?

Because I’m trying to create a overlap event in code and it won’t work with a UstaticMeshComponent attatched. I used the exact same code for a different actor but had a collision capsule instead. What has changed that stops the collision from occurring ?

Code:

Brick.cpp

Brick.cpp


#include "Mario3D.h"
#include "Brick.h"
#include "Coin.h"
#include "Engine.h"


ABrick::ABrick(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	//Brick Mesh
	static ConstructorHelpers::FObjectFinder<UStaticMesh> Mesh(TEXT("StaticMesh'/Game/Shapes/Shape_Cube.Shape_Cube'"));
	BrickMesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("BrickMeshComponent"));
	BrickMesh->SetStaticMesh(Mesh.Object);
	BrickMesh->SetWorldScale3D(FVector(0.64, 0.64, 0.64));
	RootComponent = CollisionComp;

	// Creates Collision Component
	CollisionComp = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("CollisionComponent"));
	CollisionComp->OnComponentBeginOverlap.AddDynamic(this, &ABrick::OnOverlap);
	CollisionComp->SetBoxExtent(FVector(32, 32, 1));
	CollisionComp->bGenerateOverlapEvents = true;
	UPrimitiveComponent::SetNotifyRigidBodyCollision(true);
}

void ABrick::OnOverlap(class AActor * OtherActor, class UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
{
	if (OtherActor && (OtherActor != this) && OtherComp)
	{
		// Spawn Actor & Play Sound
		ACoin* SpawnedActor2 = GetWorld()->SpawnActor<ACoin>(GetActorLocation() + FVector(0, 0, 300), FRotator(0, 0, 0));;
	}
}

Brick.h

#pragma once

#include "GameFramework/Actor.h"
#include "Brick.generated.h"

/**
 * 
 */
UCLASS()
class MARIO3D_API ABrick : public AActor
{
	GENERATED_UCLASS_BODY()
		UPROPERTY(VisibleAnywhere, Category = Brick)
		TSubobjectPtr<UBoxComponent> CollisionComp;

	UPROPERTY(VisibleAnywhere, Category = Brick)
		TSubobjectPtr<UStaticMeshComponent> BrickMesh;
	
	UFUNCTION()
		void OnOverlap(class AActor * OtherActor, class UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);
};

Coin.h



#pragma once

#include "GameFramework/Actor.h"
#include "CoinSound.h"
#include "Coin.generated.h"


/**
 * 
 */
UCLASS()
class MARIO3D_API ACoin : public AActor
{
	GENERATED_UCLASS_BODY()

		/*Declares Collision Component*/
		UPROPERTY(VisibleDefaultsOnly, Category = Coin)
		TSubobjectPtr<USphereComponent> CollisionComponent;

	UPROPERTY(VisibleDefaultsOnly, Category = Coin)
		float RotationRate;

	UPROPERTY(VisibleDefaultsOnly, Category = CoinSound)
		TSubclassOf<ACoinSound> ASound;

	virtual void Tick(float DeltaTime) override;

	/** called when coin hits something or vice versa */
	UFUNCTION()
		void OnOverlap(class AActor * OtherActor, class UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);
	
};

If you set up a static mesh with blueprint, there is a checkbox named something like “generate overlap events”.
You’re doing this with the code but should be same thing, I assume you should enable this to get it working.
Collision capsule is a component meant to be used for generating events like touch, overlap etc, so either make the StaticMesh generate overlap events or just add a collision capsule to your code. I’m sure if you try to do this with blueprint it will work, I haven’t tried this with the code yet thou.

It’s a USphereComponent sorry, not sure if it makes a difference, i’ve added the code.

Have u solve this problem?

I solve it .

u do not set the collisionResponseToChannle .