Skip to content

Add partial support for custom mouse cursors#51

Open
Sixze wants to merge 1 commit intoVesCodes:Devfrom
Sixze:custom-cursors-support
Open

Add partial support for custom mouse cursors#51
Sixze wants to merge 1 commit intoVesCodes:Devfrom
Sixze:custom-cursors-support

Conversation

@Sixze
Copy link
Copy Markdown
Contributor

@Sixze Sixze commented Mar 24, 2026

This PR adds support for custom mouse cursors, but only for InGui windows.

To implement custom mouse cursors inside the game viewport, a custom UGameViewportClient with overridden GetCursor() and IsInPermanentCapture() functions is required. Here is an unedited code from my project that can be used as an example:

EMouseCursor::Type ULmGameViewportClient::GetCursor(FViewport* InViewport, const int32 MouseX, const int32 MouseY)
{
#ifndef IMGUI_DISABLE
	const auto MouseCursor{Super::GetCursor(InViewport, MouseX, MouseY)};
	if (MouseCursor != EMouseCursor::None && MouseCursor != EMouseCursor::Default)
	{
		return MouseCursor;
	}

	const auto* DebuggerSubsystem{ULmDebuggerSubsystem::Get(GetWorld())};
	if (!IsValid(DebuggerSubsystem) || !DebuggerSubsystem->IsDebuggerEnabled())
	{
		return MouseCursor;
	}

	if (DebuggerSubsystem->IsGameInputAllowed() && MouseCursor == EMouseCursor::None)
	{
		// Preserve cursor visibility if input is not enabled.
		return MouseCursor;
	}

	const auto& WorldContext{GEngine->GetWorldContextFromGameViewportChecked(this)};
	const ImGui::FScopedContext ImGuiContext{WorldContext.PIEInstance};

	if (!ImGuiContext)
	{
		return MouseCursor;
	}

	return ImGui::ConvertMouseCursor(ImGuiContext->GetLastMouseCursor());
#else
	return Super::GetCursor(InViewport, MouseX, MouseY);
#endif
}

bool ULmGameViewportClient::IsInPermanentCapture()
{
#ifndef IMGUI_DISABLE
	const auto* DebuggerSubsystem{ULmDebuggerSubsystem::Get(GetWorld())};
	if (IsValid(DebuggerSubsystem) && !DebuggerSubsystem->IsGameInputAllowed())
	{
		return false;
	}
#endif

	return Super::IsInPermanentCapture();
}

@Sixze Sixze force-pushed the custom-cursors-support branch from 9967733 to 7c4eae9 Compare March 27, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant