Setting Custom Safezone

We want to use USafeZone in our project for adding safe zones. It gets a custom padding from the FSlateApplication.

We tried to manually set this padding using “FSlateApplication::Get().SetCustomSafeZone(InNewMargin);” and force a rebuild by calling invalidate all widgets on the slate. Please refer the code below:

FSlateApplication::Get().SetCustomSafeZone(InNewMargin);
RebuildWidget();
FSlateApplication::Get().InvalidateAllWidgets(true);
for (UWidget* CHildWidget : GetAllChildren())
{
    UE_LOG(LogTemp, Warning, TEXT("Invalidatiing %s"), *CHildWidget->GetName());
    CHildWidget->InvalidateLayoutAndVolatility();
}

However it does not work.

We are able to get workaround using “r.debugsafezone.titleratio [f]” however it does not provide flexibility to manage the Vertical and horizontal scaling/Padding seprately.

[Attachment Removed]

Steps to Reproduce

FSlateApplication::Get().SetCustomSafeZone(InNewMargin);
RebuildWidget();
FSlateApplication::Get().InvalidateAllWidgets(true);
for (UWidget* CHildWidget : GetAllChildren())
{
    UE_LOG(LogTemp, Warning, TEXT("Invalidatiing %s"), *CHildWidget->GetName());
    CHildWidget->InvalidateLayoutAndVolatility();
}

[Attachment Removed]

Hi,

It looks like we may be missing a delegate broadcast when setting a custom safe zone. Could you try calling the following after SetCustomSafeZone to see if that’s sufficient for your SafeZone widget to pick up the change?

FCoreDelegates::OnSafeFrameChangedEvent.Broadcast();Best,

Cody

[Attachment Removed]

Unfortunately the solution did not work.

Our guess is that the callback listening to the broadcast on the slate is not updating the margins.

In the FSlateApplicationBase::UpdateCustomSafeZone(const FMargin& NewSafeZoneRatio, bool bShouldRecacheMetrics) is a protected method, so can not be called from outside.

Hence we call the SetCustomSafeZone, which only does the following:

void FSlateApplicationBase::SetCustomSafeZone(const FMargin& InSafeZone)
{
    CustomSafeZoneRatio = InSafeZone;
    CustomSafeZoneState = ECustomSafeZoneState::Set;
}

Only 2 classes check the CustomSafeZoneState indirectly through the IsCustomSafeZoneSet function,

they are SlateApplicationBase and the game viewport client(editor only code here).

Inside the GetSafeZoneRatio in the FSlateApplicationBase, we return the custom safe zone ratio which if used would solve the problem. But when we call SSafeZone::UpdateSafeMargin(), the following code runs, but only inside the editor, hence the safe margin on the safe zone class itself is not set.

if (GameViewport.IsValid())
{
    TSharedPtr<ISlateViewport> ViewportInterface = GameViewport->GetViewportInterface().Pin();
    if (ViewportInterface.IsValid())
    {
       const FIntPoint ViewportSize = ViewportInterface->GetSize();
       FSlateApplication::Get().GetSafeZoneSize(SafeMargin, ViewportSize);
    }
    else 
    { 
       return;
     }
}

Best,

Tushar

[Attachment Removed]

Hi,

Sorry to get back late on this.

unfortunately it does not work with this CL.

We are currently trying with our custom solution.

Can you suggest any equivalent code changes we can do in engine to make the FSlateApplicationBase::SetCustomSafeZone work?

[Attachment Removed]

Hi,

That change ensures that the SSafeZone widget *does* actually call into Slate’s GetSafeZoneSize function, so I’d start by adding some logging there to see what size it’s getting back. This could help us narrow down where things are going wrong, and if the widget is failing to pick up the proper SafeMargin or if Slate is failing to set/retain it.

I’m not seeing anything obvious in SlateApplication’s Get/Set functions for the safe zone, is it possible that something is resetting it? I’d recommend adding some logging to all of the various safe zone functions in here to see if something is resetting it or if IsCustomSafeZoneSet does indeed return true.

Best,

Cody

[Attachment Removed]

Hi,

There should be a block under that which calls GetSafeZoneSize regardless of whether we’re in the editor. That change went in with 5.5, can you verify that you have the changes in CL#34864531? If so, it might be interesting to drop a breakpoint there and verify that SafeMargin is updating to the expected value.

Best,

Cody

[Attachment Removed]