OnCompoenentBeginOverlap.AddDynamic not working

I want to make my player to pick up a weapon by letting it enter the sphere component of the weapon. If the overlap event is triggered, it should display an error message and pick up the weapon. But it is not displaying any message or picking up the weapon when I enter the sphere component.

cpp:

// Fill out your copyright notice in the Description page of Project Settings.

#include “Components/SceneComponent.h”

#include “weapon.h”

// Sets default values
Aweapon::Aweapon(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;

RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("ROOT"));

MySphere = CreateDefaultSubobject<USphereComponent>(TEXT("sphere"));
MySphere->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);

MyWeaponMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("weapon_mesh"));
MyWeaponMesh->AttachToComponent(MySphere, FAttachmentTransformRules::KeepRelativeTransform);

DamageBox = CreateDefaultSubobject<UBoxComponent>(TEXT("BOX"));
DamageBox->AttachToComponent(MySphere, FAttachmentTransformRules::KeepRelativeTransform);

MySphere->OnComponentBeginOverlap.AddDynamic(this, &Aweapon::OnOverlapBegin);

}

// Called when the game starts or when spawned
void Aweapon::BeginPlay()
{
Super::BeginPlay();

}

void Aweapon::OnOverlapBegin(class UPrimitiveComponent* HitComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
UE_LOG(LogTemp,Error,TEXT(“OVERPLAP”))
if (OtherActor) {
APlayerCharacter*player = Cast(OtherActor);
if (player) {
MySphere->AttachToComponent(player->GetMesh(),FAttachmentTransformRules::SnapToTargetNotIncludingScale,“weapon_right”);
}
}

}

// Called every frame
void Aweapon::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

}


.h:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include “CoreMinimal.h”
#include “PlayerCharacter.h”
#include “GameFramework/Actor.h”
#include"Components/SphereComponent.h"
#include"Components/BoxComponent.h"
#include “weapon.generated.h”

UCLASS()
class RPG_PROJECT_API Aweapon : public AActor
{
GENERATED_BODY()

public:
// Sets default values for this actor’s properties
Aweapon(const FObjectInitializer& ObjectInitializer);

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

UPROPERTY(EditAnyWhere)
	USphereComponent* MySphere;

UPROPERTY(EditAnyWhere)
	USkeletalMeshComponent* MyWeaponMesh;

UPROPERTY(EditAnyWhere)
	UBoxComponent* DamageBox;
UFUNCTION()
	void OnOverlapBegin(class UPrimitiveComponent* HitComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);

public:
// Called every frame
virtual void Tick(float DeltaTime) override;

};

Try putting the AddDynamic in the BeginPlay and not in the ctor:

// Called when the game starts or when spawned 
void Aweapon::BeginPlay() 
{ 
    Super::BeginPlay();
    MySphere->OnComponentBeginOverlap.AddDynamic(this, &Aweapon::OnOverlapBegin);
}