When attached to a component, I can't get OnBeginOverlap to fire

Hi everyone!

I am having a bit of trouble understanding Overlap events when it comes to items equipped to a socket. When it is unequipped/on the ground, it has no problem firing. However, when I attach it to my Player Character, I can get the event to fire only on the opposing actor, and not my weapon.

First of all, the code on my ItemClass.cpp:

AItemClass::AItemClass()
{
	// Create the item capsule and attach it to the Root Component
	ItemCapsule = CreateDefaultSubobject<UCapsuleComponent>(TEXT("ItemCapsule"));
	 = ItemCapsule;

	// Set up the On Hit event.
	ItemCapsule->OnComponentHit.AddDynamic(this, &AItemClass::OnHit);
	ItemCapsule->OnComponentBeginOverlap.AddDynamic(this, &AItemClass::OnOverlap);
	
	// Lastly, create the Mesh component and attach it to the capsule.
	InteractableMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ItemMesh"));
	InteractableMesh->SetupAttachment();

	// Simulate physics and notify rigid body collision.
	InteractableMesh->SetSimulatePhysics(false);
	//InteractableMesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
	InteractableMesh->SetNotifyRigidBodyCollision(true);

	ItemCapsule->SetSimulatePhysics(false);
	ItemCapsule->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);

	// Can this item deal damage?
	CanDamage = false;

}

As for my “equip” settings, they are very simple:

void AItemClass::setMeshToActor(USceneComponent* Component, FName SocketName)
{
	ItemCapsule->SetSimulatePhysics(false);
	ItemCapsule->AttachToComponent(Component, FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true), SocketName);
}

As for my settings:

  • Event overlap events are enabled.

  • I’ve tried enabling and disabling physics, and from what I can tell, this only affects hit events, and not collision events

  • I have set the collision properties to overlap. I even had my weapon blanket overlap everything. I’ve created a new overlap event called Weapon, and have set everything to overlap with it, and I still haven’t managed to get it to do anything at all.

The only thing that I can think of is equipping to a socket changes settings somehow, but I can’t figure out what that is. Any help would be appreciated. Thank you!

Could it be that it overlaps the moment you attach to a socket? So it will only get called once?

Also check if you are not ignoring “self” in the overlap properties (ignore actors)

If it is not fixed after you checked this could you post your OnOverlap function?

Good luck!

Hey ,

I put together an Actor and collision is working as it should:

[.h]

#pragma once

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

UCLASS()
class AH497434_API AItemClass : public AActor
{
	GENERATED_BODY()
	
public: 
	AItemClass();
	virtual void BeginPlay() override;
	virtual void Tick( float DeltaSeconds ) override;
    
    UPROPERTY( BlueprintReadOnly, VisibleAnywhere, Category = "Collision" )
    USphereComponent *CollisionComp;

    UFUNCTION( )
    void Hit( UPrimitiveComponent* HitComponent, 
                 AActor* OtherActor, 
                 UPrimitiveComponent* OtherComp, 
                 FVector NormalImpulse,
                 const FHitResult &Hit);
    
    UFUNCTION( )
    void Overlap(UPrimitiveComponent* OverlappedComponent, 
                     AActor* OtherActor, 
                     UPrimitiveComponent* OtherComp, 
                     int32 OtherBodyIndex, 
                     bool bFromSweep, 
                     const FHitResult &SweepResult );
    
    UFUNCTION( )
    void EndOverlap( UPrimitiveComponent* OverlappedComponent, 
                    AActor* OtherActor, 
                    UPrimitiveComponent* OtherComp, 
                    int32 OtherBodyIndex );
};

[.cpp]

#include "AH497434.h"
#include "ItemClass.h"

AItemClass::AItemClass()
{
	PrimaryActorTick.bCanEverTick = true;
    CollisionComp = CreateDefaultSubobject<USphereComponent>( TEXT("Collision Component") );
    CollisionComp->OnComponentHit.AddDynamic( this, &AItemClass::Hit );
    CollisionComp->OnComponentBeginOverlap.AddDynamic( this, &AItemClass::Overlap );
    CollisionComp->OnComponentEndOverlap.AddDynamic( this, &AItemClass::EndOverlap );
    SetRootComponent( CollisionComp );
}

void AItemClass::BeginPlay()
{
	Super::BeginPlay();
	
}

void AItemClass::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

}

void AItemClass::Hit( UPrimitiveComponent* HitComponent, 
         AActor* OtherActor, 
         UPrimitiveComponent* OtherComp, 
         FVector NormalImpulse,
         const FHitResult &Hit)
{
    UE_LOG( LogTemp, Warning, TEXT("Hit( )") );
}


void AItemClass::Overlap(UPrimitiveComponent* OverlappedComponent, 
             AActor* OtherActor, 
             UPrimitiveComponent* OtherComp, 
             int32 OtherBodyIndex, 
             bool bFromSweep, 
             const FHitResult &SweepResult )
{
    UE_LOG( LogTemp, Warning, TEXT("Overlap( )") );
}


void AItemClass::EndOverlap( UPrimitiveComponent* OverlappedComponent, 
                AActor* OtherActor, 
                UPrimitiveComponent* OtherComp, 
                int32 OtherBodyIndex )
{
    UE_LOG( LogTemp, Warning, TEXT("EndOverlap( )") );    
}

Then, the log when a Character walks through it:

LogTemp:Warning: Overlap( )
LogTemp:Warning: EndOverlap( )

I am not sure what it is that I did, but I remade the item, and suddenly it worked! I wonder if constructors don’t reload at compile time?

Thanks for taking the time to answer my question!