Create a fBrush for Slate

Hi, I am attempting to use Slate to create a 50% alpha bar across the base of my screen. I have so far:

ViewportWidget->AddSlot(20)[
				SNew(SOverlay)
					+ SOverlay::Slot()
					.VAlign(VAlign_Bottom)
					.HAlign(HAlign_Fill)						
			

			[
				//Colored Background
				SNew(SBorder)
				.Padding(FMargin(3))
			//  Image for BG
			.BorderImage(FCoreStyle::Get().GetBrush("ExpandableArea.Border"))				
			.ColorAndOpacity(FLinearColor(0, 0, 0, 0.5f))
			[
				// Text
				SNew(STextBlock)
				.Justification(ETextJustify::Left)
					.Text(TestHUDText)
					.Margin(10)
					.ColorAndOpacity(FLinearColor::Red)
					.Font(FSlateFontInfo("Veranda", 16))
			]
			]
			];

The line:

.BorderImage(FCoreStyle::Get().GetBrush("ExpandableArea.Border"))	

I borrowed from a tutorial, and it works, but obviously calls an image, so I cannot adjust the alpha.

How can I either create my own brush that calls an image? OR, use .BorderImage with a solid fill color, not a png file?

Thanks!

FSlateBrush is normal struct just make one, but remember it needs to be in memory all the time when it’s used. So declere FSlateBrush in header file and set it up in initiation, best would be if you do that with FSlateBrush constructor:

there also some FSlateBrush template structs with are easier to setup specific things like just color or just image:

FSlateBrush is also blueprint compatible (as it’s used in UMG), if you make it a property you can normally set image and color in property editor.

By convention you should hold any brushes in slate style set (but they work from anywhere so you don’t need to do that if you only want one or few brush), here you have tutorial about slate style set:

I could not find any brush set example so i dig one from engine source code:
https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Plugins/2D/Paper2D/Source/Paper2DEditor/Private/PaperStyle.cpp

Thank you. SO I have:

.h

FSlateColorBrush* brushClr;

.cpp constructor:

FSlateColorBrush brushClr = FSlateColorBrush(FLinearColor::White);

and in the slate code:

ViewportWidget->AddSlot(20)[
				SNew(SOverlay)
					+ SOverlay::Slot()
					.VAlign(VAlign_Bottom)
					.HAlign(HAlign_Fill)


					[
						//Colored Background
						SNew(SBorder)
						.Padding(FMargin(3))
						.BorderImage(brushClr)

This compiles, but nothing shows up. Where is my (probably stupid) mistake?

thank you yet again for your help.

Hmmm i think you need to set DrawAs to Border

Also header deceleration should not be pointer we want to hold data in object, remove *. And you decelere it once again in cpp?

ok, so I changed the .h declare to:

FSlateColorBrush brushClr = FSlateColorBrush(FLinearColor::White);

and removed it from the cpp.

Now it will not compile, giving:

initializing': cannot convert from 'const FSlateBrush' to 'const FSlateBrush *'

It seems to expect a pointer?

Give slate pointer to brush

.BorderImage(&brushClr)

ah of course. That works great. Thanks again!