Hello,
I am trying to have a simple sphere colliding with my Character.
My Character as Collision Preset PAWN
and my Sphere the following code :
Weapon.h
UFUNCTION()
virtual void OnSphereEndOverlap(
UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex
);
Weapon.cpp
#include "Components/SphereComponent.h"
#include "Components/WidgetComponent.h"
#include "Vakamai/Character/PlayerCharacter.h"
AWeapon::AWeapon()
{
PrimaryActorTick.bCanEverTick = false;
bReplicates = true;
WeaponMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("WeaponMesh"));
WeaponMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block);
WeaponMesh->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Ignore);
WeaponMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
WeaponMesh->SetupAttachment(RootComponent);
SetRootComponent(WeaponMesh);
InteractionSphere = CreateDefaultSubobject<USphereComponent>(TEXT("InteractionSphere"));
InteractionSphere->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
InteractionSphere->SetCollisionEnabled(ECollisionEnabled::NoCollision);
InteractionSphere->SetupAttachment(RootComponent);
}
void AWeapon::BeginPlay()
{
Super::BeginPlay();
if (HasAuthority())
{
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Authority"));
InteractionSphere->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
InteractionSphere->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap);
InteractionSphere->OnComponentBeginOverlap.AddDynamic(this, &AWeapon::OnSphereBeginOverlap);
//InteractionSphere->OnComponentEndOverlap.AddDynamic(this, &AWeapon::OnSphereEndOverlap);
}
if (PickupWidget)
{
PickupWidget->SetVisibility(false);
}
}
void AWeapon::OnSphereBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("OnSphereBeginOverlap"));
APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor);
if (PlayerCharacter && PickupWidget)
{
PickupWidget->SetVisibility(true);
}
}
void AWeapon::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
I Enter the Authority, so the event and all should be set, but I never get to see my OnSphereBeginOverlap
.
Both my Character and Sphere are set to “Generate Overlap Event”. My Sphere trigger is large, and when I tried to use blueprint event “OnActorBeginOverlap” it triggered, but not the callback in my code.
What I am missing ?