# How to Make Custom Textured Buttons Using HUD C++?

**URL:** <https://forums.unrealengine.com/t/how-to-make-custom-textured-buttons-using-hud-c/275678>\
**Category:** UI\
**Tags:** unreal-engine, slate, question, CPP\
**Created:** [March 11, 2014, 2:39am UTC](https://forums.unrealengine.com/t/how-to-make-custom-textured-buttons-using-hud-c/275678 "2014-03-11T02:39:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:39am UTC](https://forums.unrealengine.com/t/how-to-make-custom-textured-buttons-using-hud-c/275678/1 "2014-03-11T02:39:27Z")

</div>

I want to make my own button class, complete with images, text, and mouse hit-detection. But I don’t want to have to do this using Slate, which is cumbersome.

If only there were someone out there who offered thorough and exhaustive tutorials at every opportunity!

[Pssst … Rama … That’s your cue! 🙂]

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:39am UTC](https://forums.unrealengine.com/t/how-to-make-custom-textured-buttons-using-hud-c/275678/2 "2014-03-11T02:39:27Z")

</div>

I am developing a fully functional HUD sample that uses custom buttons and text, so it will be a bit longer 🙂

#❤

Rama

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:39am UTC](https://forums.unrealengine.com/t/how-to-make-custom-textured-buttons-using-hud-c/275678/3 "2014-03-11T02:39:28Z")

</div>

Dear Mothership and Community,

**My C++ HUD Tutorial is Done!**

> This is a fully functional plug and  
> play HUD class of more than 800 lines  
> of C++ code for you to use as a  
> template for your UE4 projects, enjoy!

My solution does not use a button class, I use a USTRUCT() instead, because this is more streamlined given the way I setup the rest of my HUD code, and because the amount of data I store in a button is tiny.

If you choose to implement a button class to make the drawing of the title and the background of the button more connected to the actual button boundaries feel free to post your modified version 🙂

#video

===================================

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/d/4/7d4b4da45ff8d8ddf5569b6d877a76cee1eeece5.jpeg "Sample HUD For You") ](https://www.youtube.com/watch?v=85Rp4Xb2Ja0)

===================================

The **main menu background actually glows** through constant Hue shifts, it is a material with an entertaining node setup 🙂

#tooltips

In particular notice how the **tool tips appear by the cursor** and **move with the cursor** as cursor moves around within the boundaries of the button 🙂

* * *

#Pic

 ![samplehud.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/c/1/ac1b9defa03860150aa97b5e2bd56300bacd7c76.jpeg)

#800+ Lines of C++ Code For You

> **[UDK Forums Update](https://forums.unrealengine.com/t/udk-forums-update/1155689?p=31779222&viewfull=1)**
>
> The Unreal Development Kit (UDK) was released over 13 years ago and a lot has changed over the last decade—it’s been quite a journey from the burgeoning days of UDK to the unbelievable projects built in UE5. And now, after many years in stasis,...

#Description

In this tutorial I am giving you a fully functional 800+ lines of sample HUD class that features

-multiple convenience functions for

**=== Drawing ===**

- drawing textures
- drawing materials
- drawing lines
- drawing rectangles
- drawing text

The functions use the new UE4 method of using CanvasItems.

**=== Centering ==**

- how to draw stuff centered in the screen (used by confirm dialog)

**=== Rest of Game Code Integration ===**  
I have code in the tutorial to show you how to get a reference to your custom PC or Character class from within the HUD.

From your PC reference you can get access to your custom Game Mode and Game State classes (using the Cast\<\> code I show in tutorial PostInit)

**=== Player Keyboard,Mouse,Controller Input ===**

- How to capture player key presses for ANY key,mouse,controller that you want from within the HUD  
in this tutorial code,

**ESC:** clears the screen lock so camera will move with cursor.

**F:** Toggle screen lock so only the cursor moves as player moves the mouse.

**H:** Toggles hiding the HUD

**LMB:** Clicks on buttons

**Y:** Confirm yes if confirm dialog open

**N:** Cancel if confirm dialog is open

**=== Text Size ==**  
How to measure text, accounting for scaling and font size, to size backgrounds,buttons,tooltips appropriately

**=== Buttons ===**

- a button system and corresponding USTRUCT

**=== Cursor ===**

- how to draw cursor that player can move in-game

- how to change cursor when hovering over button

**=== Tooltips ===**

- button tooltips

**== Drawing Images/Textures/Materials ===**

- drawing custom button and menu backgrounds that come from textures/materials

- how to stop camera from moving as player moves mouse cursor in-game

#Code Sample, all 800+ lines at link above

```
//===============
// Cursor In Buttons
//===============
int32 AJoyHUD::CheckCursorInButton(const TArray& ButtonArray)
{
	for(int32 b = 0; b < ButtonArray.Num(); b++)
	{
		CurCheckButton = &ButtonArray[b];
			
		//check cursor in bounds
		if (CurCheckButton->minX <= MouseLocation.X && MouseLocation.X <= CurCheckButton->maxX &&
			CurCheckButton->minY <= MouseLocation.Y && MouseLocation.Y <= CurCheckButton->maxY )
		{
			
			//Active Button Type
			ActiveButton_Type = CurCheckButton->type; 
			
			//Tool Tip
			ActiveButton_Tip = CurCheckButton->toolTip; 
			
			//Change Cursor
			CursorHoveringInButton = true;
		
			//Mouse Clicked?
			if (ThePC->WasInputKeyJustPressed(EKeys::LeftMouseButton))
			{
				return ActiveButton_Type;
				// ~~~~~~~~~~~~~~
				//no need to check rest of buttons
			}
		}
	}
	
	//No Click Occurred This Tick
	return -1;	
}

//Check Confirm
void AJoyHUD::CheckCursorInButtonsConfirm()
{
	//Check Confirm Buttons
	ClickedButtonType = CheckCursorInButton(ButtonsConfirm); //fills global ActiveButton_Type
	
	if(ClickedButtonType == BUTTONTYPE_CONFIRM_YES )
	{
		ThePC->ConsoleCommand("Exit");
		return;
	}
	if(ClickedButtonType == BUTTONTYPE_CONFIRM_NO)
	{
		ConfirmDialogOpen = false;
		ButtonsConfirm.Empty(); //Buttons not needed anymore
		return;
	}
}

//Check Buttons
void AJoyHUD::CheckCursorInButtonsMain()
{
	//Check Confirm Buttons
	ClickedButtonType = CheckCursorInButton(ButtonsMain);

	if(ClickedButtonType == BUTTONTYPE_MAIN_RESTART )
	{
		ThePC->ConsoleCommand("RestartLevel");
		return;
	}
	if(ClickedButtonType == BUTTONTYPE_MAIN_EXIT)
	{
		ConfirmDialogOpen = true;
		return;
	}
}
void AJoyHUD::DrawHUD_CheckCursorInButtons()
{
	if(ConfirmDialogOpen)
	{
		CheckCursorInButtonsConfirm();
		
		//Take Focus Away From All Other buttons
		return; 
		// ~~~~
	}
	
	//Main
	CheckCursorInButtonsMain();
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ac78c893](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ac78c893](https://forums.unrealengine.com/u/anonymous_user_ac78c893)\
**Post date:** [April 14, 2014, 5:44pm UTC](https://forums.unrealengine.com/t/how-to-make-custom-textured-buttons-using-hud-c/275678/4 "2014-04-14T17:44:52Z")

</div>

There’s a problem with the link you give above - it says I do not have permission, even though I do have an account…

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [April 14, 2014, 8:01pm UTC](https://forums.unrealengine.com/t/how-to-make-custom-textured-buttons-using-hud-c/275678/5 "2014-04-14T20:01:42Z")

</div>

#Wiki Version

[A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums](https://wiki.unrealengine.com/HUD,_Canvas,_Code_Sample_of_800%2B_Lines),_Create\_Buttons_%26\_Draw\_Materials

Enjoy!

Rama

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ac78c893](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ac78c893](https://forums.unrealengine.com/u/anonymous_user_ac78c893)\
**Post date:** [April 15, 2014, 3:37pm UTC](https://forums.unrealengine.com/t/how-to-make-custom-textured-buttons-using-hud-c/275678/6 "2014-04-15T15:37:02Z")

</div>

thanks for your work, Rama! It has been invaluable!

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [April 15, 2014, 6:20pm UTC](https://forums.unrealengine.com/t/how-to-make-custom-textured-buttons-using-hud-c/275678/7 "2014-04-15T18:20:43Z")

</div>

hee hee!

😉

Rama

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_adc3f730](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_adc3f730](https://forums.unrealengine.com/u/anonymous_user_adc3f730)\
**Post date:** [September 14, 2014, 9:00pm UTC](https://forums.unrealengine.com/t/how-to-make-custom-textured-buttons-using-hud-c/275678/8 "2014-09-14T21:00:03Z")

</div>

I dont know if you code is outdated or something but i doesnt work when i follow the steps

it gives me every error possible “ERROR : example is undifined” etc…
