I want to attach a box component to the front of my character that calls a function when it overlaps with a custom interactable class derived from actor. How would I go about doing this? So far I have this in my character cpp file…
InteractableCollisionShape = CreateDefaultSubobject<UBoxComponent>(TEXT("interactable collision box"));
InteractableCollisionShape->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
InteractableCollisionShape->SetCollisionResponseToAllChannels(ECR_Ignore);
InteractableCollisionShape->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
InteractableCollisionShape->bGenerateOverlapEvents = true;
InteractableCollisionShape->OnComponentBeginOverlap.AddDynamic(this, &AMyCharacter::onInteractableHit);
InteractableCollisionShape->SetupAttachment(GetMesh());
This is stuff I’ve gathered from different tutorials, but its mostly just me blindly throwing darts at a dart board. I dont know what I need to get rid of or change. Any help would be greatly appreciated.
(Its important the collision box is attached to the character and not the object so that the function it is only called when the player is facing that object, not just in its area. Also a line trace doesn’t work because its too finicky with different sized and shaped objects.)