- Start by creating a unique collision Channel for the Item object's collision primitive. This is under Settings | Project Settings | Collision:
- Once there, create a new Object Channel by going to New Object Channel....
- Name the new Object Channel Item and set the Default Response to Overlap. Afterwards, hit the Accept button:
- Take your Item actor and select the primitive component on it that is used to intersect for pickup with the player avatar. From the Details tab, go to the Collision section and under Collision Presets, change the option to Custom.... Afterwards, set the Object Type of that primitive to Item.
- Check the Overlap checkbox against the Pawn class Object Type, as shown in the following screenshot:
- Ensure that the Generate Overlap Events checkbox is checked:
Location of the Generate Overlap Events property.
- Take the player actor who will pick up the items (BP_Warrior for this example) and select the component on them that feels for the items. Usually, this will be their CapsuleComponent. Check Overlap with the Item object:

- Now, the Player overlaps the item, and the item overlaps the player pawn. We do have to signal overlaps both ways (Item overlaps Pawn and Pawn Overlaps Item) for it to work properly. Ensure that Generate Overlap Events is also checked for the Pawn intersecting component.
- Next, we have to complete the OnComponentBeginOverlap event for either the item or the Player's pickup volume, using either Blueprints or C++ code:
- If you prefer Blueprints, in the Events section of the Details pane of the Items's intersectable Component, click on the + icon beside the On Component Begin Overlap event:

-
- Use the OnComponentBeginOverlap event that appears in your Actor Blueprint diagram to wire in Blueprints code to run when an overlap with the Player's capsule volume occurs.
- If you prefer C++, you can write and attach a C++ function to the CapsuleComponent. Write a member function in your player's Character class (for example, the Warrior.h file) with a signature, as follows:
UFUNCTION(BlueprintNativeEvent, Category = Collision)
void OnOverlapsBegin(UPrimitiveComponent* Comp,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult&SweepResult);
UFUNCTION(BlueprintNativeEvent, Category = Collision)
void OnOverlapsEnd(UPrimitiveComponent* Comp,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex);
virtual void PostInitializeComponents() override;
-
- Complete the implementation of the OnOverlapsBegin() function in your .cpp file, making sure to end the function name with _Implementation:
void AWarrior::OnOverlapsBegin_Implementation(
UPrimitiveComponent* Comp,
AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep, const FHitResult&SweepResult)
{
UE_LOG(LogTemp, Warning, TEXT("Overlaps warrior
began"));
}
void AWarrior::OnOverlapsEnd_Implementation(
UPrimitiveComponent* Comp,
AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex)
{
UE_LOG(LogTemp, Warning, TEXT("Overlaps warrior
ended"));
}
-
- Then, provide a PostInitializeComponents() override to connect the OnOverlapsBegin() function with overlaps to the capsule in your avatar's class, as follows:
#include "Components/CapsuleComponent.h"
// ...
void AWarrior::PostInitializeComponents()
{
Super::PostInitializeComponents();
if (RootComponent)
{
// Attach contact function to all bounding components.
GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &AWarrior::OnOverlapsBegin);
GetCapsuleComponent()->OnComponentEndOverlap.AddDynamic(this, &AWarrior::OnOverlapsEnd);
}
}
- Compile your script and then run your project. You should see log messages when you enter and leave the object! Refer to the following screenshot: