Help With Lyra's CommonUI system. Trying to make a cursor widget.

Hi guys I am currently working on a customized version of Lyra Starter Game. I am refactoring it to work as a top down with a mouse point and click style. Now for the most part I understand how to change most things. Unfortunately, when it comes to the input system of enhanced input along with common UI then I need to create a software cursor if you will. I will be using a widget that is an Activatable widget class to consume the input from the pointer. What is the best way for me to update this widget though. Right now, I have it set up with the correct tags and everything so when I press play it shows the widget cursor where the extension point is on my Hud layout. but how would I go about updating that cursor widgets screen position? I understand how to get my current mouse position and what not but for whatever reason I am having a hard time figuring out where I should implement the logic to update the cursor Widgets screen position every frame.

Any help or insight would be appreciated!

Maybe there is a better way, but I did this in Lyra in C++ using the NativeTick function in the Widget.

Each NativeTick I read the mouse position and then SetRenderTransform on the mouse cursor widget (adjusting mouse position for UI scale).

FVector2D ViewportSize;
float ViewportScale;
const bool bKnownViewportInfo = GetViewportSizeAndScale(OUT ViewportSize, OUT ViewportScale);

if (bKnownViewportInfo && MouseTrackingComponent.IsValid())
{
    const FVector2D Position = MouseTrackingComponent->GetPosition2D();
    const float NotZeroScale = FMath::IsNearlyZero(ViewportScale)
        ? 1.f : ViewportScale;

    FWidgetTransform Transform;
    Transform.Translation = Position / NotZeroScale;

    SetRenderTransform(Transform);
}

You won’t have my MouseTrackingComponent, but you get the idea.

1 Like

Thank you so much for sharing your solution. I was working with a friend to achieve something similar. But we used Blueprints to implement it.

So far the small system is based on a simple user widget that is moved around with the mouse. It supports clamping the widget location to the screen borders. Additionally, the UMG widget location is converted to screenspace and then to world space to fire line traces.

Line trace precision

Implementation

Mouse Tracker Component