OnClicked.AddDynamic is not calling the binded function when clicked.

I have this code:

// Detects Click Events
LeverMesh->OnClicked.AddDynamic(this, &ALever::OnLeverPulled);

And I have this code in my character:

void AMicheal::Click(const FInputActionValue& Value)
{
const bool ClickValue = Value.Get();

FVector Location
    FVector Direction;
Cast<APlayerController>(GetController())->DeprojectMousePositionToWorld(Location, Direction);

FHitResult HitResult;
Reach = Location + Direction * 1000;
const bool HitButton = GetWorld()->LineTraceSingleByChannel(HitResult, Location, Reach, ECC_GameTraceChannel1);
if (HitButton)
{
	UE_LOG(LogTemp, Log, TEXT("Hit Actor: %s"), *HitResult.GetActor()->GetName());
}

}

The LineTrace IS detecting the Lever, but its not calling the OnClicked Function. Ive Tried moving it to BeginPlay and the COnstructor but nothing seems to be working. Any Ideas?

Alright, I had to use another method to fix this:

First, I got rid of the OnClicked.AddDynamic Function and Just Left the Function Alone.

In My Character Class, I did a Cast to the Lever, So I can use it in my Character Class
// Call the lever’s OnLeverPulled function
ALever* Lever = Cast(HitResult.GetActor());
if (Lever)
{
Lever->OnLeverPulled();
}

And this did do the trick. Hope it helps you too!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.