Hey everyone so I am trying to get my item actor class to have working collision with the players pawn. Here is the cpp file
#include "ItemActor.h"
// Sets default values
AItemActor::AItemActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
// Create the root component
Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
SetRootComponent(Root);
// /\
// Create the mesh component
Mesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Mesh"));
Mesh->SetupAttachment(Root);
// /\
// Create the collision sphere
CollisionSphere = CreateDefaultSubobject<USphereComponent>(TEXT("CollisionSphere"));
CollisionSphere->SetupAttachment(Mesh);
CollisionSphere->SetSphereRadius(70.0f);
CollisionSphere->SetGenerateOverlapEvents(true);
CollisionSphere->SetCollisionProfileName(TEXT("Item"));
CollisionSphere->OnComponentBeginOverlap.AddDynamic(this, &AItemActor::OnOverlapBegin);
}
// Called when the game starts or when spawned
void AItemActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AItemActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AItemActor::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Turquoise, TEXT("Overlapped"));
// Get the inventory component from the other actor
UInventoryComponent* PlayerInventory = OtherActor->FindComponentByClass<UInventoryComponent>();
if (PlayerInventory)
{
PlayerInventory->AddItem(Item);
Destroy();
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("No Inventory Component Found"));
}
}
I am trying to get it to work with the Item profile I have here
But I can’t get the overlap function to work.
BUT, if I got into the blueprint event graph of the item actor child, I can use the OnActorOverlap node and that works fine. But mine doesn’t, what am I missing? Any help would be greatly appreciated, that you in advance!
