Download

Mouse Release Non-Hitbox

Maybe I’m blind but I can’t find it. What are the Mouse Click and Release events that do not involve hitboxes (like AHUD::ReceiveHitBoxRelease). I’ve noticed that ReceiveHitBoxRelease doesn’t fire if the mouse is no longer in the hitbox after a click. Is there a global mouse release somewhere?

EDIT: I see this available in the HUD blueprint, I’m trying to find the equivalent code

When you say equivalent code, you mean how to Bind those actions in C++?

In your HUD code, you would want to construct a UInputComponent and assign it to InputComponent, and then call BindKey on it.

I’m going to jot down a note to look at/think about whether ReceiveHitBoxRelease should be called even if you’re no longer over a HitBox and just provide None as the name.

Yes, I wanted to know how to do “Left Mouse Pressed/Released” in code. I will read up on UInputComponent and try that.

I don’t know your architecture, but isn’t the bConsumeInput bool there to prevent the input to bubble up to the next level of priority? I was thinking that you should have catch all events at the end of the bubbling up chain, maybe as a static event you could subscribe to?

EDIT: Or have OnClick and OnRelease equivalents implemented in UObject as catch-alls. Probably with different names tho to avoid conflicts with AActor::OnClick/OnRelease

Is this what I should be doing? For some reason, it is not working. Anything else I should be turning on to get the event?



void AGameHUD::BeginPlay() {
	UE_LOG(LogClass, Log, TEXT("AGameHUD::BeginPlay"));
	InputComponent = ConstructObject<UInputComponent>(UInputComponent::StaticClass(), this, TEXT("HUD_InputComponent0"));
	if (InputComponent) {
		UE_LOG(LogClass, Log, TEXT("AGameHUD::BeginPlay BindKey"));
		InputComponent->BindKey(EKeys::LeftMouseButton, IE_Pressed, this, &AGameHUD::OnLeftMouseButtonClick);
	}

}

void AGameHUD::OnLeftMouseButtonClick() {
	UE_LOG(LogClass, Log, TEXT("AGameHUD::OnLeftMouseButtonClick"));
}


EDIT: ofc I’m testing click before I implement release

Ok this works:



void AGameHUD::BeginPlay() {
	UE_LOG(LogClass, Log, TEXT("AGameHUD::BeginPlay"));
	InputComponent = ConstructObject<UInputComponent>(UInputComponent::StaticClass(), this, TEXT("HUD_InputComponent0"));
	if (InputComponent) {
		UE_LOG(LogClass, Log, TEXT("AGameHUD::BeginPlay BindKey"));
		InputComponent->BindKey(EKeys::LeftMouseButton, IE_Pressed, this, &AGameHUD::OnLeftMouseButtonClick);
		InputComponent->BindKey(EKeys::LeftMouseButton, IE_Released, this, &AGameHUD::OnLeftMouseButtonRelease);
		InputComponent->BindKey(EKeys::LeftMouseButton, IE_DoubleClick, this, &AGameHUD::OnLeftMouseButtonDoubleClick);

		GetOwningPlayerController()->PushInputComponent(InputComponent);
	}

}

void AGameHUD::OnLeftMouseButtonClick() {
	UE_LOG(LogClass, Log, TEXT("AGameHUD::OnLeftMouseButtonClick"));
}

void AGameHUD::OnLeftMouseButtonDoubleClick() {
	UE_LOG(LogClass, Log, TEXT("AGameHUD::OnLeftMouseButtonDoubleClick"));
}

void AGameHUD::OnLeftMouseButtonRelease() {
	UE_LOG(LogClass, Log, TEXT("AGameHUD::OnLeftMouseButtonRelease"));
}


Thanks for the code Dejan, that helped me a lot!