How to set the image in SBorder ?

I’m trying to set the BorderImage to SBorder, but it appears only if i create the style in code,game module… that excess.
Instead of the normal I get a white image. File path is correct.
I think the problem is in the place of the initialization…
**What is the most simple way to get and set the image to SBorder ? **

Can I use FObjectFinder and FSlateDynamicImageBrush insted FSlateImageBrush ?
like

.Image(new FSlateDynamicImageBrush(NewTexture, FVector2D(128, 128), FName(*TexturePath)));

how ?

my slate

SNew(SBorder)
	.HAlign(HAlign_Center)
	.VAlign(VAlign_Center)
	.BorderImage(this, &SMyUIWidget::GetSecondImageBrush)
	[
		SNew(STextBlock)
		.Font(FSlateFontInfo("Veranda", 54))
		.ColorAndOpacity(FLinearColor(1, 1, 1, 1))
		.Text(FText::FromString("Page Two"))
	]

my function

const FSlateBrush* SMyUIWidget::GetSecondImageBrush() const
{
	FString PathToImage;

	(SecondTabActive == 0) ? PathToImage = TEXT("Slate/tab_normal.png") : PathToImage =      TEXT("Slate/tab_active.png");

	FString ImagePath = FPaths::GameContentDir() / PathToImage;
	FName BrushName = FName(*ImagePath);

	return new FSlateImageBrush(BrushName, FVector2D(256, 64));
}

UPD: the easiest way to set an image is to use the FSlateDynamicImageBrush looks like this:

UTexture2D* tabActiveImage;
UTexture2D* tabPassiveImage;

FSlateDynamicImageBrush* tab_active;
FSlateDynamicImageBrush* tab_normal;
...
AMyHUD::AMyHUD(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	ConstructorHelpers::FObjectFinder<UTexture2D> activeImage(TEXT("Texture2D'/Game/Slate/tab_active.tab_active'"));
	tabActiveImage = activeImage.Object;

	ConstructorHelpers::FObjectFinder<UTexture2D> passiveImage(TEXT("Texture2D'/Game/Slate/tab_normal.tab_normal'"));
	tabPassiveImage = passiveImage.Object;

	tab_active = new FSlateDynamicImageBrush(tabActiveImage, FVector2D(256, 64), FName("tabActiveImage"));
	tab_normal = new FSlateDynamicImageBrush(tabPassiveImage, FVector2D(256, 64), FName("tabPassiveImage"));
}
...
const FSlateBrush* SMyUIWidget::GetFirstImageBrush() const
{
	if (FirstTabActive == 0)
	{
		return tab_normal;
	}
	else
	{
		return tab_active;
	}
}
...
	SNew(SBorder)
		.HAlign(HAlign_Center)
		.VAlign(VAlign_Center)
		.BorderImage(this, &SMyUIWidget::GetFirstImageBrush)
		[
                ...
		]

Have you looked into Slate style sets (see FSlateStyleSet)? The ShooterGame has a sample of using one of these in a game (see FShooterStyle), and CoreStyle.cpp shows how you’d set image brushes up using them (see IMAGE_BRUSH).

This allows the textures to be atlased correctly by Slate, as well as ensuring that they’re not unloaded again while still in use. It also allows you to store your brushes and other style data in a central place, whereas your current method of allocating a new brush in your delegate will actually leak memory as nothing is freeing the allocation you’re returning.

Yes, I do as in the shooter game. Always need to create a style? this is the only way? I just thought can be made easier as:

const ConstructorHelpers::FObjectFinder<UTexture> MyImage(TEXT("/Path"));

and when

.BorderImage(this, MyImage)

something like this is impossible?

You can create a brush that references a UTexture or UMaterial by using the SetResourceObject function on FSlateBrush. If you were going to do this you’d probably want to make the FSlateBrush instance a member of your widget so you can just return a pointer to it, rather than allocating and leaking memory as you’re doing now. You’d also be responsible for making sure the source texture was loaded and referenced so that it didn’t get garbage collected.

If you’re wanting to use a texture from disk, you pretty much have to use a FSlateStyleSet as they provide all their resources to the renderer so that the textures get loaded. Because this isn’t happening right now, you’re seeing a white texture.