[Slate] Odd widget flickering when running as standalone game

I’ve added some placeholder UI indicators in the game. It looks fine when you choose Play In / New Window At / Default Player Start, but there’s a weird flicker effect when you run it as a Standalone Game, as if it’s only being rendered every other frame. Why might this be?

bug_flickering.png

Oddly, it only seems to be in my app; it doesn’t happen in the StrategyGame example.

you have the editor closed when you run standalone instance?

Nope, and I don’t want to. I am trying to do that from the editor, as one of the options under “Play In.”

I have now reproduced this in a standalone instance as well. Right-clicking the uproject and selecting “Launch Game” produces exactly the same results.

Update: this seems to be related to alpha transparency. I am seeing that the flickering only happens in the areas with alpha – UI elements that are semi-transparent flicker completely, while solid UI elements with semi-transparent outlines flicker only around their semi-transparent edges.

In order to be of much help, can you provide some code that demonstrates how you have setup your UI that flickers? We don’t know of any bugs related to flickering in Slate when using alpha so either you have discovered one or there is some setup problem.

OK – I basically just copied the appropriate parts of the code from the way Slate is used in the StrategyGame example.

I tested various theories that this might be caused by my UI widget textures having different properties than in the StrategyGame example, or not being power-of-2 in size, but those turned out to make no difference. I also tried doing file diffs of my code vs. the corresponding files in StrategyGame but didn’t find anything that could resolve the flickering.

So, here’s the code. First, I have a function in my HUD called BuildWidgets() that builds the Slate UI the normal way; BuildWidgets() gets called inside DrawHUD():

SAssignNew(MasterHUDMenuWidget, SOCMasterHUDWidget)
	.OwnerHUD(this);

if (MasterHUDMenuWidget.IsValid())
{
	GEngine->GameViewport->AddViewportWidgetContent
	(
		SNew(SWeakWidget)
		.PossiblyNullContent(MasterHUDMenuWidget.ToSharedRef())
	);
}

Second, I have a button class, which is literally a copied-and-pasted-and-very-slightly-modified version of SStrategyButtonWidget from StrategyGame.

I did have to slightly modify SetImage() on the button class like so, to allow rescaling:

void SOCButton::SetImage(UTexture2D* Texture, float const scale)
{
	if ( scale != m_RescaleFactor)
	{
		SetScale( scale );
	}

	if (Texture)
	{
		ButtonImage.Reset();
		ButtonImage = TSharedPtr(new FSlateDynamicImageBrush(Texture,
			FVector2D(Texture->GetSizeX(),Texture->GetSizeY()),Texture->GetFName()));
		ButtonImage->ImageSize.X *= m_RescaleFactor;
		ButtonImage->ImageSize.Y *= m_RescaleFactor;
		AlphaMap.Reset();
		AlphaMap = CreateAlphaMapFromTexture(Texture);
	}

	DeferredShow();
}

and that new CreateAlphaMapFromTexture() is derived directly from FStrategyHelpers::CreateAlphaMapFromTexture():

TSharedPtr>  SOCButton::CreateAlphaMapFromTexture(UTexture2D* Texture)
{	
	TSharedPtr> ResultArray;

	// create temporary hitmask
	if (Texture && Texture->GetPixelFormat() == PF_B8G8R8A8 && Texture->GetNumMips() == 1)
	{
		const int32 HitMaskSize = Texture->GetSizeX() * Texture->GetSizeY();

		ResultArray = TSharedPtr>(new TArray());
		ResultArray->Init(255, HitMaskSize);
	}

	return ResultArray;
}

Finally, I have my master HUD widget that sets up all the other stuff in its Construct(), and sets up the buttons like so:

		+SOverlay::Slot()
		.VAlign(VAlign_Bottom)
		.HAlign(HAlign_Right)
		.Padding(FMargin(0,0,30,14))
		[
			SAssignNew(m_BuildPaletteBackground,SOCButton)
			.OwnerHUD(OwnerHUD)
			.Visibility(EVisibility::HitTestInvisible)
		]

Have you at least tried running standalone instance without the editor running?

I encounter frame rate issues when I run standalone game and Editor at same time. And imagine there are other performance issues as well, perhaps including what you are describing.

It would provide us all with good test data if you could at least try this :slight_smile:

just right click on the .uasset for your game (with editor not running) :slight_smile:

Rama

It’s not a frame rate issue; it’s a flickering issue. When I run STAT FPS, I get the same performance as I do with Play In > New Window in the editor.

And yes, I’m right-clicking on the .uproject and selecting “Launch Game” to run it.

… And I’d like to believe it’s something I’m doing, but it seems to be a pretty generic implementation of Slate, pulled straight from the StrategyGame example and the tutorials on the forums.

FYI, this bug is still happening in beta 6.

Without having a reproducible case to look at, the only thing else I can think of for you to check is that make sure DeferredShow() and DeferredHide() are not being called continuously somehow causing it to flicker by being hidden and shown, that your opacity value remains constant, and to make sure SetImage isn’t being called constantly (always recreating the brush and extremely expensive btw). This all assumes you are using the strategy button widget in the same way.

Argh. I’d really hoped one of these would be it, but …

  • DeferredShow() is only getting called when the button image changes.
  • The button image is only getting set inside my master HUD widget’s Construct() function, which is only getting called once, as it should.
  • I’ve tried removing every single reference to opacity from the button class – so that, for example, every callback that would return an FSlateColor returns a value with 100% alpha.

And it still flickers.

This is driving me nuts … if it keeps up I’ll try to find a way to copy this to a separate project so you guys can take a look at it.

The button class is truly identical to the one in StrategyGame, only much simpler since I’ve stripped so much out.

So it must be something else to do with the integration of Slate into the game somehow, only I have no idea what it could be since I’ve checked the master HUD widget we’re using and the way it’s being constructed by the HUD itself and they both seem identical to the StrategyGame.