How to change Z-order between UMG widgets and "draw elements" from OnPaint/NativePaint?

I have a UMG widget class inheriting from UUserWidget. In this widget, I am drawing some elements by overriding the NativePaint function (also known as OnPaint in Blueprint).

The drawing code is something very standard like this (simplified for readability):

int32 UMyWidget::NativePaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const
{
	// Draw some curves on the AllotedGeometry
	for (/* some loop */) FSlateDrawElement::MakeSpline(OutDrawElements, LayerId, AllottedGeometry.ToPaintGeometry(), /* the rest doesn't matter */ );
	++LayerId

	return Super::NativePaint(/* same args */);
}

This works fine, and the draw elements show up. The problem is, they are always drawn on top of widgets I add to this widget in UMG (so, all UMG widgets are are behind all DrawElements).

I assume something like the Z-Order, or the LayerID variable, could be responsible for this? Or is the graphics pipeline hard-coded to draw UMG first, and the OnPaint stuff second?

Is it possible to order these Draw Elements behind the rest of the UMG elements?

Did you ever figure this out? I’m having the same issue. I tried subtracting from the LayerId which works but it sometimes causes asserts in the rendering code, so it must not be safe.

I just had the same problem and this is how I solved it: I moved paint code into another widget, place that widget into original widget under widget I wanted it to draw under.