I am hoping to change Tooltips using the engine present so that they no longer update based on the mouse position, but are attached to the hovered object that spawned them. Hopefully with some kind of behaviour on how to present (above/below, left/right etc).
It seems like the code to override is the tooltip presenter OnArrangeChildren function so that when the GameLayerManager Sets the Content in OnVisualizeTooltip we could pass through and cast to our custom STooltipWidget class and based on flags within that class, present the tooltip anchored to a ParentWidget (custom member) based on its FAnchors data (custom member).
I have attempted three different methods of trying to change how the default tooltip position is updated.
At first I tried creating a custom SGameLayerManager and setting it to the TWeakPtr GameLayerManagerPtr; in the GameViewportClient then trying to set the TSharedPtr TooltipPresenter; but this is a private member that cannot be accessed. Was hoping maybe I could overload it using a similar syntax to overloading some internals for actors using the Initializer lists e.g
Super(Initializer.SetDefaultSubobjectClass<UCrowdFollowingComponent>(TEXT("PathFollowingComponent")))
However this is a SWidget object which does not have the same initializer list setup.
I was then poking about the code and found the ToolTipForcefield functionality which I thought might be close enough to allow us to set a flag on specific UI where the tooltip would use its Cached geometry to place itself somewhere away from the object spawning the tooltip. So I added in a simple function that
void
UMyBlueprintFunctionLibrary::AddTooltipForceField( UWidget* widget )
{
TSharedPtr<SWidget> SafeWidget = widget->GetCachedWidget();
if( SafeWidget.IsValid() )
{
SafeWidget->EnableToolTipForceField( true );
widget->SynchronizeProperties();
}
}
Howeever this doesn’t seem to cause any change either.
I cannot overload the OnPaint in Blueprint to try and change the RenderTransform of the Widget to decrement the mouse position from the UI position of the parent widget, as this is a const function.
If I do the required maths and update within the Tick of the TooltipWidget then I get a flickering due to the cached geometry being one frame behind the new mouse position and its offset being laggy.
Not sure where to go from here, I know I can write a custom solution and spawn a new UserWidget during the OnHovered and remove it when OnUnhovered and manage all the despawn/ownership rules with every UI, but the simplicity of using Unreals existing system for tooltips woulda been cool/easier. Hopefully someone out there might have done up a method for how to expose/override these classes and might have some advice.
Thanks