[FREE] Custom Shaped Buttons (Custom Hit Box for any button)

Thank you for this solution. This was one of the most important missing features of UMG. But like mentioned before it doesn’t work while the button borders are overlapping. It detects only the top button. ıs there any way to fix that?

There are still more issues with this button. Especially when pressing the button and leaving it with the mouse -> Then release the mouse button.

Here are my files, implemented as a module. I renamed the button to HitScanButton, still with credits and link to this site.
You will now also get a MessageLog spam when you did not setup the hit texture correctly.

Hi, do you mind making a plugin for 4.19 version? I will thank you very much.

Hi! Thanks u for this tutorial. This button will not work for mobile application. So i little modified u code for mobile. See attachments

If you really want an overlaping odd-shaped button and want to click under the button’s area, you’d better fix engine… It is possible.

Can you update links please

i made some change ,so that button can overlap each other, hover and unhover on the intersaction work properly, but need set overlap buttons for each button.

Still wish we had this in plugin format or something.

plugin provided for ue4.19

1 Like

Hi @flame_7777 , do you by chance have a version of the code or plugin that will work with 4.26?

2 Likes

HI @Anonymous_22f547d62f00bac65c2343d67ba1c173 Any chance you can make a version of the plugin for 4.26 please? I would be very grateful as I’m sure many others would be.
Thank you hugely in advance.

Hi all, the code not working in shipping application, anyone else?

Hello,
Posting here in case somebody is still interested.
I’ve managed to make it work in shipping builds on UE5.0.1 with the following code:

if (AdvancedHitTexture->GetPlatformData()->Mips[0].BulkData.IsBulkDataLoaded()) {
		FColor* ImageData = reinterpret_cast<FColor*>(AdvancedHitTexture->GetPlatformData()->Mips[0].BulkData.Lock(LOCK_READ_ONLY));

		if (!ImageData) {
			WhatToReturn = false;
		}
		else {
			if (ImageData[BufferPosition].A <= AdvancedHitAlpha) WhatToReturn = false;
		}
		AdvancedHitTexture->GetPlatformData()->Mips[0].BulkData.Unlock();
	}
  • reinterpret_cast: seems to be the only way to have it compile for shipping
  • IsBulkDataLoaded(): prevents the code from accessing the texture data until it’s ready into memory. I’m not sure, but it seems to me that Unreal blocks you forever from locking the pixels if just once you try to get them when they are not ready

Also make sure that the texture you are using is set to:

  • Compression: Vector displacement map (RGBA8)
  • MipMaps: no mipmaps
  • sRGB: disabled

Hi thanks you so much for this comment!
But I have a question because i’m not very good i C++. Where I have to put this code you have posted?

I worked on an older version of the code that is no longer available to download. Looking at the last plugin posted in this discussion however it could be enough to replace the static_cast instruction with a reinterpret_cast one but I haven’t tested it yet.

If you want to try:
Create a code project, download the plugin and place it in the plugins folder. Then navigate the plugin’s folders and find the AlphaButton.cpp file inside the Private directory. In that file search for “static_cast” (should be in the SAlphaButton::IsMouseOverOpaquePixel function) and replace “static_cast” with “reinterpret_cast”.
On the older version of the plugin I’m using it was enough to make it compile for shipping.

1 Like

我将作者的代码转为了插件,并且在4.26版本上可以使用:

The existing code seems to be outdated for Unreal Engine 5 and lacks necessary support. I’ve addressed these issues by rewriting it into an open-source plugin.
It works for 2D and 3D widgets and tested on Windows and Mac including shipping builds.

Your contributions or issue reports on the GitHub repository are highly welcomed, ensuring its continued update for new engine versions.

The plugin, along with a Sample Project demo and documentation, can be downloaded using the following link:

4 Likes