UE小:UE5的Pixelstreaming在捕获画面的时候没办法显示非Viewport的Slate区域按钮的ToolTip

原始代码

首先,让我们看看原始代码片段:

cpp 复制代码
// Some widgets might want to provide an alternative Tooltip Handler.
if (bCanSpawnNewTooltip || !NewTooltip)
{
    TSharedPtr<SWidget> NewTooltipWidget = NewTooltip ? NewTooltip->AsWidget() : TSharedPtr<SWidget>();
    for (int32 WidgetIndex = WidgetsToQueryForTooltip.Widgets.Num() - 1; WidgetIndex >= 0; --WidgetIndex)
    {
        const TSharedRef<SWidget>& CurWidget = WidgetsToQueryForTooltip.Widgets[WidgetIndex].Widget;
        if (CurWidget->OnVisualizeTooltip(NewTooltipWidget))
        {
            // Someone is taking care of visualizing this tooltip
            NewTooltipVisualizer = CurWidget;
            break;
        }
    }
}

修改后的代码

现在,我们来看一下修改后的版本:

cpp 复制代码
// Some widgets might want to provide an alternative Tooltip Handler.
if (bCanSpawnNewTooltip || !NewTooltip)
{
    TSharedPtr<SWidget> NewTooltipWidget = NewTooltip ? NewTooltip->AsWidget() : TSharedPtr<SWidget>();
#if (UE_BUILD_SHIPPING || UE_BUILD_DEBUG)
    FVector2D WindowInitialDesiredSize =  SlateApp.GetTopLevelWindows()[0]->GetInitialDesiredSizeInScreen();
    FVector2D  ViewportSize = SlateApp.GetTopLevelWindows()[0]->GetViewport()->GetSize();
    FWidgetPath WidgetsUnderCursor = SlateApp.LocateWindowUnderMouse(FVector2D (ViewportSize.X-170,63), SlateApp.GetInteractiveTopLevelWindows(), /*bIgnoreEnabledStatus =*/true, UserIndex);
    for (int32 WidgetIndex = WidgetsUnderCursor.Widgets.Num() - 1; WidgetIndex >= 0; --WidgetIndex)
    {
        const TSharedRef<SWidget>& CurWidget = WidgetsUnderCursor.Widgets[WidgetIndex].Widget;
        if (CurWidget->OnVisualizeTooltip(NewTooltipWidget))
        {
            // Someone is taking care of visualizing this tooltip
            NewTooltipVisualizer = CurWidget;
            break;
        }
    }
#else
    for (int32 WidgetIndex = WidgetsToQueryForTooltip.Widgets.Num() - 1; WidgetIndex >= 0; --WidgetIndex)
    {
        const TSharedRef<SWidget>& CurWidget = WidgetsToQueryForTooltip.Widgets[WidgetIndex].Widget;
        if (CurWidget->OnVisualizeTooltip(NewTooltipWidget))
        {
            // Someone is taking care of visualizing this tooltip
            NewTooltipVisualizer = CurWidget;
            break;
        }
    }
#endif
}

主要原因

主要看当前的要显示ToolTip的区域是否有一个SVirtualWindow,如果有就将ToolTip显示在SVirtualWindow之内就行,否则的话NewTooltipVisualizer将不会赋值,导致的后果就是他会新生成一个SWindow,独立于Pixelstreaming的TargetWindow,而Pixelstreaming只捕获TargetWindow画面,所以导致看到的画面中没有ToolTip并且伴随着闪烁,如果显卡能力稍弱一点可能会导致崩溃

解决的办法

就是将调用显示ToolTip的逻辑中插入每次都检测一个固定位置,这个固定位置是一定包含SVirtualWindow的就行(比如我就是将WidgetsToQueryForTooltip替换为了我自己通过位置检测的位置获得的FWidgetPath,这个位置是在Viewport中放置的一个按钮)

相关推荐
17岁的勇气1 天前
Unity Shader unity文档学习笔记(二十二):shader变体
笔记·学习·unity
寂寞的船2 天前
【Unity知识速递】第10期 Unity GC 零分配实战:从 UnityEngine.Pool 到手动 GC 控制的全链路优化
jvm·unity·c#·游戏引擎·lucene
Martina_03213 天前
AI生成3D场景的霓虹灯一开就糊成光团?用6步检查Emissive、Bloom与曝光
人工智能·3d·ai·自然语言处理·游戏引擎·材质·贴图
寂寞的船4 天前
【Unity知识速递】第8期 IL2CPP 托管堆内存碎片与原生堆交互机制深度解析
unity·游戏引擎·交互
寂寞的船5 天前
【Unity知识速递】第5期 Unity 6.2 深度解析:AI Assistant 登场,World Space UI 与 Sentis 全面升级
人工智能·ui·unity
寂寞的船5 天前
【Unity知识速递】第4期 MCP for Unity:用 AI 自然语言控制编辑器
人工智能·unity·编辑器
淡海水5 天前
09-04-内存-Unity原生对象生命周期
unity·c#·游戏引擎·gc
寂寞的船5 天前
【Unity知识速递】第6期 URP性能优化完全指南:从内存到GPU的三维调优
unity·性能优化·编辑器
寂寞的船5 天前
【Unity Bug挑战】第10期 SerializeReference 内存泄漏之谜
unity·c#·游戏引擎·bug
tealcwu7 天前
【Unity基础】为什么游戏需要物理按键映射?从 Unity Input Manager 到跨引擎输入设计
java·游戏·unity