# BeginOverlap function does not get called for the character C++ CapsuleComponent

**URL:** <https://forums.unrealengine.com/t/beginoverlap-function-does-not-get-called-for-the-character-c-capsulecomponent/434063>\
**Category:** C++\
**Tags:** oncomponentbeginover, unreal-engine, UE4, CPP, question\
**Created:** [September 19, 2018, 11:48am UTC](https://forums.unrealengine.com/t/beginoverlap-function-does-not-get-called-for-the-character-c-capsulecomponent/434063 "2018-09-19T11:48:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohit\_Agrawal](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mohit\_Agrawal](https://forums.unrealengine.com/u/Mohit_Agrawal)\
**Post date:** [September 19, 2018, 11:48am UTC](https://forums.unrealengine.com/t/beginoverlap-function-does-not-get-called-for-the-character-c-capsulecomponent/434063/1 "2018-09-19T11:48:26Z")

</div>

Hi I am trying to achieve when a simple character who when presses a button within a trigger opens a door.  
I am trying to use the character capsule component which for the collision with trigger. But i cannot seem to fire the Overlap function call. Although the same is happening in blueprints.

Here’s My Code

## MyCharacter.h

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "MyCharacter.generated.h"

UCLASS()
class DARKHORSEUNREAL_API AMyCharacter : public ACharacter
{
	GENERATED_BODY()

	/** First person camera */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
	class UCameraComponent* FirstPersonCameraComponent;

	/** Base turn rate*/
	UPROPERTY(VisibleAnywhere, Category = "Camera")
	float BaseTurnRate;

	/** Base look up/down rate */
	UPROPERTY(VisibleAnywhere, Category = "Camera")
	float BaseLookUpRate;

```

//Creating a variable to store and call the capsule component from ACharacter class  
UPROPERTY(VisibleAnywhere, Category = “Capsule”)  
class UCapsuleComponent\* CollisionCapsule;

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

	//Handles moving forward/backward
	void MoveForward(float Val);

	//Handles stafing movement, left and right
	void MoveRight(float Val);

	//Handles the input for door closing/opening
	void DoorAction();

public:
	// Constructor-Sets default values for this character's properties
	AMyCharacter();

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

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

	UFUNCTION()
	virtual void OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
};

```

## MyCharacter.cpp

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

#include "MyCharacter.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/InputComponent.h"
#include "Engine/World.h"

// Sets default values
AMyCharacter::AMyCharacter()
{
 	// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	BaseTurnRate = 45.f;
	BaseLookUpRate = 45.f;

	FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FPPCamera")); //Assigning the camera
	FirstPersonCameraComponent->SetupAttachment(GetCapsuleComponent());
	FirstPersonCameraComponent->RelativeLocation = FVector(-39.56f, 1.75f, 64.f); // Position the camera
	FirstPersonCameraComponent->bUsePawnControlRotation = true;

	CollisionCapsule = GetCapsuleComponent();
	CollisionCapsule->OnComponentBeginOverlap.AddDynamic(this, &AMyCharacter::OnOverlapBegin);

}

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

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

}

// Called to bind functionality to input
void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	check(PlayerInputComponent);

	//Bind the DoorAction Event
	PlayerInputComponent->BindAction("DoorAction", IE_Pressed, this, &AMyCharacter::DoorAction);

	// Bind jump events
	PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
	PlayerInputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping);

	// Bind movement events
	PlayerInputComponent->BindAxis("MoveForward", this, &AMyCharacter::MoveForward);
	PlayerInputComponent->BindAxis("MoveRight", this, &AMyCharacter::MoveRight);

	//Binding The Mouse Axis events
	PlayerInputComponent->BindAxis("Turn", this, &APawn::AddControllerYawInput);
	PlayerInputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput);
}

void AMyCharacter::MoveForward(float Val)
{
	if (Val != 0.0f)
	{
		AddMovementInput(GetActorForwardVector(), Val);
	}
}

void AMyCharacter::MoveRight(float Val)
{
	if (Val != 0.0f)
	{
		AddMovementInput(GetActorRightVector(), Val);
	}
}

void AMyCharacter::DoorAction()
{
	UE_LOG(LogTemp, Warning, TEXT("E Pressed"));
}

void AMyCharacter::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	UE_LOG(LogTemp, Warning, TEXT("Overlap Begins"));
}

```

---

<div class="post-metadata">

**Author:** ![HarryHighDef](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HarryHighDef](https://forums.unrealengine.com/u/HarryHighDef)\
**Post date:** [September 19, 2018, 12:12pm UTC](https://forums.unrealengine.com/t/beginoverlap-function-does-not-get-called-for-the-character-c-capsulecomponent/434063/2 "2018-09-19T12:12:04Z")

</div>

Try moving where you assign the begin overlap to begin play

---

<div class="post-metadata">

**Author:** ![Mohit\_Agrawal](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mohit\_Agrawal](https://forums.unrealengine.com/u/Mohit_Agrawal)\
**Post date:** [September 19, 2018, 2:26pm UTC](https://forums.unrealengine.com/t/beginoverlap-function-does-not-get-called-for-the-character-c-capsulecomponent/434063/3 "2018-09-19T14:26:45Z")

</div>

Thanks That Fixed the Problem.

But i would like to know why it worked on Begin Play and not through the constructor

---

<div class="post-metadata">

**Author:** ![HarryHighDef](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HarryHighDef](https://forums.unrealengine.com/u/HarryHighDef)\
**Post date:** [September 19, 2018, 2:34pm UTC](https://forums.unrealengine.com/t/beginoverlap-function-does-not-get-called-for-the-character-c-capsulecomponent/434063/4 "2018-09-19T14:34:03Z")

</div>

The constructor is run when the class is created. So the event your are assigning doesn’t exist during the constructor but does during begin play.

---

<div class="post-metadata">

**Author:** ![Mohit\_Agrawal](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mohit\_Agrawal](https://forums.unrealengine.com/u/Mohit_Agrawal)\
**Post date:** [September 21, 2018, 3:17pm UTC](https://forums.unrealengine.com/t/beginoverlap-function-does-not-get-called-for-the-character-c-capsulecomponent/434063/5 "2018-09-21T15:17:38Z")

</div>

Thanks a lot.
