C++ Event OnActorClicked

Hello world !

I’m trying to do some stuff in C++. What I want is to click on an actor, and moving him with the Set Actor Location.

I followed this code that I found on google:

.h file:

     //Static Mesh Component to interact with
 UPROPERTY(VisibleAnywhere)
 UStaticMeshComponent* CustomMeshComponent;
 
    //Function to handle the interaction
 UFUNCTION()
 void CustomOnBeginMouseOver(UPrimitiveComponent* TouchedComponent);

.cpp file, in constructor:

 CustomMeshComponent = CreateDefaultSubobject(TEXT("Test Component"));
 CustomMeshComponent->AttachTo(RootComponent);
 CustomMeshComponent->OnBeginCursorOver.AddDynamic(this, &AMyActor::CustomOnBeginMouseOver);

then:

 void AMyActor::CustomOnBeginMouseOver(UPrimitiveComponent* TouchedComponent)
 {
     if (GEngine)
     {
     GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Cyan, TEXT("Mouse Over"));
     }
 }

But nothing happened.

Thanks a lot guys :slight_smile: