stegoboston
Topic Author
Posts: 3
Joined: 19 Feb 2019, 03:37

Managing UI Hit-Boxes / Focus in UE4

20 Feb 2019, 21:27

Hello and thanks for your time,
I've been struggling finding a way to deal with the UI consuming mouse events in UE4. if anyone could give me suggestions on how to approach this issue:

Image

There's a sphere on the scene which should respond to a mouse over event and I've added a NoesisInstance to the viewport which should also receive input events from the mouse. The sphere responds to mouse over events only if the NoesisIsntance is not added to viewport.

The issue i'm having is that the presence of the NoesisInstance is preventing the sphere from receiving the mouse-over event as if there is an overlay stretched across the entire screen. I've been looking into sizing the UserWidget element so that the frame of the widget could be the boundary for the hit test but I can't find out how to access this. Looking at the C++ for for NoseisInstance class it seems to have code to autosize itself to the size of the XAML but I'm not sure how to trigger this.

An example of the game usage would be a UI element for each party member on the side of the screen. Party members could be clicked on in the world to select but also clicking on their party frame element would also select them. Both the world or the UI would be selectable depending on what the mouse is over.

The XAML:
<UserControl x:Class="MainWindow.MainWindow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:MainWindow"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800" Width="200" Height="200">
    <UserControl.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="Black" Offset="0"/>
            <GradientStop Color="#FF3E5191" Offset="1"/>
        </LinearGradientBrush>
    </UserControl.Background>
    <TextBlock x:Name="textBlock" Margin="23.283,112.1,23.283,65.762" TextWrapping="Wrap" Text="Box for testing Hit-Tests" Width="153.434" TextAlignment="Center" FontWeight="Bold"/>
</UserControl>
Thanks for the help!
 
User avatar
hcpizzi
Site Admin
Posts: 321
Joined: 09 Feb 2012, 12:40

Re: Managing UI Hit-Boxes / Focus in UE4

21 Feb 2019, 17:11

Hi stegoboston,

This has come up in the past. Unfortunately, while click events are well handled by the engine, and if you try clicking on the sphere you'll get the mouse enter/leave events too, it doesn't handle move events that well.

The solution we've given in the past involves implementing your own player controller class in C++ and overriding the function IsInViewportClient like this:
bool IsInViewportClient(UGameViewportClient* ViewportClient) const override
{
	return Super::IsInViewportClient(ViewportClient) || NoesisIsViewportHovered(ViewportClient);
}
There's a discussion about this on this forum thread: viewtopic.php?f=3&t=1273&p=7584&hilit=P ... ller#p7584

Unfortunately the engine level solution I proposed there didn't work and it breaks some of the engine UI in the editor, which I only noticed afterwards.

Unfortunately at the moment the solution only works with native C++ code. If you're using Blueprint only, I want to see if this workaround can be implemented in a blueprint too.
 
stegoboston
Topic Author
Posts: 3
Joined: 19 Feb 2019, 03:37

Re: Managing UI Hit-Boxes / Focus in UE4

21 Feb 2019, 22:38

Hello hcpizzi,
First off I just wanted to say thank you so much, I've made a few posts since I began working with Noesis and you've answered all off them and have been a huge help,

Yes, you're describing the problem exactly as if i click on the Sphere it does trigger the MouseOver event but simply moving the mouse over it does nothing. I work in C++ so I can give that a shot, I'm not entirely sure what the fix does, I'm assuming that bool function is used by UE4 in detecting of the Mouse is Over something.

After trying it the reverse now happens where the Sphere trigger's it's mouse over event but the box no longer blocks input. I'm still learning XAML so the box not blocking the hover could be due to a setting I don't know about yet.

MVS is also reporting this breaking point after the change:
TSharedRef<SWidget> TopmostWidget = HitTestResults.GetLastWidget();.
I'll post my PlayerController class with the changes discussed in case I made a mistake there:

Control.h
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
// Noesis includes
#include "NoesisSDK.h"
#include "Control.generated.h"

/**
*
*/
UCLASS()
class NOESISLEARN_API AControl : public APlayerController
{
GENERATED_BODY()

public:
bool IsInViewportClient(UGameViewportClient* ViewportClient) const override
{
return Super::IsInViewportClient(ViewportClient) || NoesisIsViewportHovered(ViewportClient);
}
};
Thank you so much for your help and time!
 
User avatar
hcpizzi
Site Admin
Posts: 321
Joined: 09 Feb 2012, 12:40

Re: Managing UI Hit-Boxes / Focus in UE4

02 Mar 2019, 04:12

Hi stegoboston,

No worries, we're here to help. Sorry about the late reply, but we've been pushing to get the final 2.2 version out.

I've made a couple of changes to the plugin to make this work. I've added a test to prevent the crash you were experiencing, and there was also a problem with the hit test code itself.

The code's been pushed to the master, 4.21 and 4.21-2.2 branches on GitHub.

Please, let us know if you run into any other problems, and sorry again about the late reply.

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 36 guests