Description

Binding a function in code to OnComponentBeginOverlap, OnComponentEndOverlap, or OnComponentHit does not trigger the bound function from code.

Steps to Reproduce
  1. Open UE4 Editor (any project)
  2. Add new code class based on actor (MyActor)
  3. In MyActor.h add the following:
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Test)
    		USphereComponent* SphereComp;
    
    	UFUNCTION(BlueprintCallable, Category = Test)
    	void SphereFunc(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
    
  4. Add the following to MyActor.cpp
    • Add include statement
      #include "Engine.h"
      
    • Add to Constructor
      SphereComp = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComp"));
      SphereComp->OnComponentBeginOverlap.AddDynamic(this, &AMyActor::SphereFunc);
      
    • Add new function below tick function
      void AMyActor::SphereFunc(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
      {
      	if (GEngine)
      	{
      		GEngine->AddOnScreenDebugMessage(-1, 4.f, FColor::Red, TEXT("Overlap"));
      	}
      }
      
  5. Compile
  6. In the editor, create a blueprint of MyActor (MyActorBP)
  7. Add instance of MyActorBP to the level (set hidden in game to false)
  8. PIE and walk into the sphere

Result:
Bound SphereFunc doesn't print Overlap message

Expected:
When OnComponentOverlap triggers, function bound in code triggers as well.

Repro Rate:
3/3

Have Comments or More Details?

Head over to the existing Questions & Answers thread and let us know what's up.

2
Login to Vote

Cannot Reproduce
ComponentUE - Gameplay - Components
Affects Versions4.11.2
Target Fix4.12
CreatedApr 25, 2016
ResolvedApr 25, 2016
UpdatedApr 27, 2018
View Jira Issue