# Slate Tutorial

**URL:** <https://forums.unrealengine.com/t/slate-tutorial/732>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [March 24, 2014, 7:13am UTC](https://forums.unrealengine.com/t/slate-tutorial/732 "2014-03-24T07:13:51Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [March 31, 2014, 9:45pm UTC](https://forums.unrealengine.com/t/slate-tutorial/732/22 "2014-03-31T21:45:00Z")

</div>

I added a request in the Feedback section for more Slate info

> **[Slate Documentation, Editor, and Blueprint Access](https://forums.unrealengine.com/showthread.php?1710-Slate-Documentation-Editor-and-Blueprint-Access)**
>
> Hello, The UI is currently a major weakness in the engine simply because it is under-documented and difficult to understand. The source code does provide some examples on the use of Slate, but it incorporates overly complex use cases that do not...

EDIT: And now there is a poll, go vote 😃

---

<div class="post-metadata">

**Author:** ![Agentleo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Agentleo](https://forums.unrealengine.com/u/Agentleo)\
**Post date:** [April 1, 2014, 1:21am UTC](https://forums.unrealengine.com/t/slate-tutorial/732/23 "2014-04-01T01:21:03Z")

</div>

I will see if I have time to put something together tonight and post it here.

---

<div class="post-metadata">

**Author:** ![Agentleo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Agentleo](https://forums.unrealengine.com/u/Agentleo)\
**Post date:** [April 1, 2014, 8:20am UTC](https://forums.unrealengine.com/t/slate-tutorial/732/24 "2014-04-01T08:20:17Z")

</div>

> [@](#):
>
> Hey, thanks for the offer, but I agree that info should be shared here or on the wiki. For the moment I am getting by without Slate, but a complete example of the following is of interest to me:
> 
> - How start a project that is a Slate Application, but with an Unreal viewport (e.g. like the actual Unreal Editor, but that is easier to understand, without the bloat). Maybe something like the SlateViewer, but with a viewport and blueprint support
> 
> - How to make a menu in-game (MenuBar). Where is it created, how to have callbacks
> 
> - How to make popups and dialogs
> 
> - How to make image browser controls
> 
> Just as a start 🙂

- How to make a menu in-game (MenuBar). Where is it created, how to have callbacks

This is explained in Slate documentation you use FMenuBuilder below is an example of a Menu being created when a button is clicked  
without using FReply parameters.

```auto

SNew(SButton)
.OnClicked(this, &Class::OnOpenClicked )

TSharedRef<SWidget> Class::OnOpenClicked()
{
	FMenuBuilder MenuBuilder(commands);
	{ 
		//create Menu items
	}

       //create and return Menu widget
	return MenuBuilder.MakeWidget();
}

```

As I get further into Slate I am pretty amazed by it. If you look at SWidgetGalley , and SLayoutExamples it provides examples on most of the widgets you need to get started. I just wait fool around with a few more things over next few days and then I may make a simple Menu

---

<div class="post-metadata">

**Author:** ![Agentleo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Agentleo](https://forums.unrealengine.com/u/Agentleo)\
**Post date:** [April 4, 2014, 1:35am UTC](https://forums.unrealengine.com/t/slate-tutorial/732/25 "2014-04-04T01:35:54Z")

</div>

Below is a very simplified example of creating a Menu using FMenuBuilder. I have a more advance system in place in my personal project but without having time to create an actual tutorial most of what I am doing and why would not be understood. This should help people understand FMenuBuilder widget in slate and a simple callback of OnClicked.

```auto

#pragma once

#include "Slate.h"

class SMenu: public SCompoundWidget

public:
	SLATE_BEGIN_ARGS(SMenu)
	{}

	SLATE_END_ARGS()

		// Constructor for slate widgets
		void Construct(const FArguments& InArgs);

private:

	//Start button callback 
	FReply StartBtnClicked();

//Options button callback 
        FReply OptionsBtnClicked();

//Credits button callback 
        FReply CreditsBtnClicked();

//Exit button callback 
        FReply ExitBtnClicked();

//Function to Create Menu 
	TSharedRef<SWidget> MyMenu();
};

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SMenu.cpp
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include SMenu.h

// Constructor
void SMainMenu::Construct(const FArguments& InArgs)
{
	
	
	ChildSlot
		
			SNew(SOverlay)

//create slot on overlay for Menu
			+ SOverlay::Slot()
			.HAlign(HAlign_Center)
			.VAlign(VAlign_Center)
			
			// create Menu widget
					MyMenu()	
			]	
		];

}

TSharedRef<SWidget> SMainMenu::MyMenu()
{
	FMenuBuilder MenuBuilder(true, NULL, TSharedPtr<FExtender>(), false, &FCoreStyle::Get());
	{
	
	
		MenuBuilder.AddWidget(SNew(SButton)
			.Text(FText::FromString("Start"))
			.OnClicked(this, &SMainMenu::StartBtnClicked)
			, FText::GetEmpty());

		MenuBuilder.AddWidget(SNew(SButton)
			.Text(FText::FromString("Options"))
			.OnClicked(this,&SMainMenu::OptionsBtnClicked)
			, FText::GetEmpty());

		MenuBuilder.AddWidget(SNew(SButton)
			.Text(FText::FromString("Credits"))
			.OnClicked(this,&SMainMenu::CreditsBtnClicked)
			, FText::GetEmpty());

		MenuBuilder.AddWidget(SNew(SButton)
			.Text(FText::FromString("Exit"))
			.OnClicked(this,&SMainMenu::ExitBtnClicked)
			, FText::GetEmpty());
	}

	return MenuBuilder.MakeWidget();

}

//Start button callback 
FReply SMenu::StartBtnClicked()
{

	return FReply::Handled();

}

//Options button callback 
FReply SMenu::OptionsBtnClicked()
{

	return FReply::Handled();

}

//Credits button callback 
FReply SMenu::CreditsBtnClicked()
{

	 return FReply::Handled();

}

//Exit button callback 
FReply SMenu::ExitBtnClicked()
{

	return FReply::Handled();

}

```

![menusimple.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/f/3/f3aac9386d9b783f75f3d8f39020e3d29419dcc4.jpeg)

---

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [April 4, 2014, 1:00pm UTC](https://forums.unrealengine.com/t/slate-tutorial/732/26 "2014-04-04T13:00:13Z")

</div>

Thanks for this, it is very useful. Where would this code be called from to create it? A BeginPlay() somewhere?

---

<div class="post-metadata">

**Author:** ![StrangerGwenn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/strangergwenn/32/983202_2.png) [@StrangerGwenn](https://forums.unrealengine.com/u/StrangerGwenn)\
**Post date:** [April 4, 2014, 7:20pm UTC](https://forums.unrealengine.com/t/slate-tutorial/732/27 "2014-04-04T19:20:24Z")

</div>

I can’t follow the tutorial with my project. Every include just breaks, no .h is ever found, no matter where, it’s a disaster. How do you even build the thing without having an error on each include file ? Where are you supposed to really put the sources ? In the private, public, classes folder ? Project root ? C:\Windows\System32 ?

The sample MyHUD.h file references the Widget class without any include. This does not work and I can’t begin to understand why it should.

Seriously, how do you build that ?

---

<div class="post-metadata">

**Author:** ![Agentleo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Agentleo](https://forums.unrealengine.com/u/Agentleo)\
**Post date:** [April 4, 2014, 9:25pm UTC](https://forums.unrealengine.com/t/slate-tutorial/732/28 "2014-04-04T21:25:16Z")

</div>

The above is just the swidget not the HUD class you can create the swidget in your HUD class using defaulthud = yourhudclass::staticclass();

In regards to your personal files default location vs uses is project directory. You can move files to your project source folder but you must include the projects header as first include.

---

<div class="post-metadata">

**Author:** ![StrangerGwenn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/strangergwenn/32/983202_2.png) [@StrangerGwenn](https://forums.unrealengine.com/u/StrangerGwenn)\
**Post date:** [April 4, 2014, 9:57pm UTC](https://forums.unrealengine.com/t/slate-tutorial/732/29 "2014-04-04T21:57:22Z")

</div>

Yeah I know, it just does not work. Whatever I do, there is no way to include MyUIWidget.h, wether from the global Project.h or the MyUIWidget.cpp, if the .h is in the Private folder. If it is in the Public folder, the compiler requires me to uinclude the MyUIWidget.generated.h, which does not exist.

EDITED : Current solution is to put all Slate code in Private and include ProjectName/Private/SlateFileName.h from the main ProjectName.h file.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0dc1700e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0dc1700e](https://forums.unrealengine.com/u/anonymous_user_0dc1700e)\
**Post date:** [April 5, 2014, 2:08am UTC](https://forums.unrealengine.com/t/slate-tutorial/732/30 "2014-04-05T02:08:21Z")

</div>

> [@Gwenn;12372](#):
>
> Yeah I know, it just does not work. Whatever I do, there is no way to include MyUIWidget.h, wether from the global Project.h or the MyUIWidget.cpp, if the .h is in the Private folder. If it is in the Public folder, the compiler requires me to uinclude the MyUIWidget.generated.h, which does not exist.
> 
> EDITED : Current solution is to put all Slate code in Private and include ProjectName/Private/SlateFileName.h from the main ProjectName.h file.

@Gwenn you aren’t going to have a MyUIWidget.generated.h. I don’t even have one of those in my tutorial, #include MyUIWidget.generated.h isn’t part of any of my files. Also, what do you mean by “public folder” or “private folder”. The tutorial states the files go in /projectroot/sources/projectname/, wherever that is on your C: D: E: drive (whatever) depends on your own setup, but really you could put them wherever you want and edit the #include directive appropraitely, some basic knowledge of filesystems is of course required.

!UPDATE!  
I have some new code-samples up for screening. It isn’t on the front wiki page yet. It’s taken me so long to get some work out because I had a hardware failure, I’ve been racing trying to get my environment back to where it was, reinstall Windows, everything installed, download visual studio, stabilize my new hardware/bios settings, install drivers, re-write all the code I lost, re-produce some programmer art, re-download UE4 and all the sample projects, write new code etc etc, etc etc… But here they are, description is within, highly recommended you master Hello Slate first before trying to tackle it, this is quite a bit more complicated.  
[https://wiki.unrealengine.com/Loading\_Slate\_Styles\_%26\_Resources](https://wiki.unrealengine.com/Loading_Slate_Styles_%26_Resources)

---

<div class="post-metadata">

**Author:** ![StrangerGwenn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/strangergwenn/32/983202_2.png) [@StrangerGwenn](https://forums.unrealengine.com/u/StrangerGwenn)\
**Post date:** [April 5, 2014, 7:43am UTC](https://forums.unrealengine.com/t/slate-tutorial/732/31 "2014-04-05T07:43:16Z")

</div>

Hey, thank you so much for all of this. I wrote a tutorial on UDK some years ago, I know the hassle it can be. I did a clean rebuild with a correct file structure; no Classes or Private folders like in the ShooterGame demo, but with hard includes to my files in \<ProjectName\>.h, and this seems to work. Working on your style tutorial right now, thanks !

---

<div class="post-metadata">

**Author:** ![StrangerGwenn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/strangergwenn/32/983202_2.png) [@StrangerGwenn](https://forums.unrealengine.com/u/StrangerGwenn)\
**Post date:** [April 5, 2014, 9:33am UTC](https://forums.unrealengine.com/t/slate-tutorial/732/32 "2014-04-05T09:33:08Z")

</div>

Ok, so here is some feedback !

- Some /////File: comments are wrong, if you understand what you’re doing it’s not an issue but is could mislead people
- Having function bodies from different classes in the same file, like SMyUIWidget:: and FMyUIResources:: looks wrong to me. Sure it works, but it’s neither clean nor necessary IMHO.

Aside from that, THANK YOU, this is really great.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0dc1700e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0dc1700e](https://forums.unrealengine.com/u/anonymous_user_0dc1700e)\
**Post date:** [April 6, 2014, 4:20am UTC](https://forums.unrealengine.com/t/slate-tutorial/732/33 "2014-04-06T04:20:08Z")

</div>

I believe the MyProject.cpp file was commented as MyProject.h . Fixed.

Thanks.

---

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [April 8, 2014, 2:19am UTC](https://forums.unrealengine.com/t/slate-tutorial/732/34 "2014-04-08T02:19:35Z")

</div>

Bleak, thanks for the tutorial. I’ve been trying to follow it, however, I get the following assert when I try and compile in the editor:

```auto

[2014.04.08-02.16.33:007][713]LogWindows:Error: appError called: Assertion failed: !FindSlateStyle( SlateStyleName ) [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.0\Engine\Source\Runtime\Slate\Private\SlateStyleRegistry.cpp] [Line: 12]

```

Seems related to loading a style, but where is this style located?

---

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [April 8, 2014, 9:32pm UTC](https://forums.unrealengine.com/t/slate-tutorial/732/35 "2014-04-08T21:32:35Z")

</div>

Specifically, it’s this line in MyGameResources.cpp that causes the crash on compile:

```auto

FSlateStyleRegistry::RegisterSlateStyle(*MyUIResources);

```

Ideas?

---

<div class="post-metadata">

**Author:** ![Agentleo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Agentleo](https://forums.unrealengine.com/u/Agentleo)\
**Post date:** [April 9, 2014, 2:58am UTC](https://forums.unrealengine.com/t/slate-tutorial/732/36 "2014-04-09T02:58:02Z")

</div>

Just glancing at his code did you update the path info for your slate project? Also would check to make sure myUIresouce pointer is not null at the point .

---

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [April 9, 2014, 3:32pm UTC](https://forums.unrealengine.com/t/slate-tutorial/732/37 "2014-04-09T15:32:53Z")

</div>

> [@Agentleo;14679](#):
>
> Just glancing at his code did you update the path info for your slate project? Also would check to make sure myUIresouce pointer is not null at the point .

The path might be the issue, as well as initialization. I’m still confused as to which path goes where.

As a side note, I see other AnswerHub questions relating to this, one from Gwenn here, which I also have been experiencing:

> **[\[Slate\] Editor crash after successfully recompiling in-editor](https://forums.unrealengine.com/questions/25033/slate-editor-crash-after-successfully-recompiling.html)**
>
> I have a (otherwise perfectly working) projects that will not compile in-editor. More exactly it compiles, but the editor crashes immediatly after compiling. I did not launch the game or start PIE, this happens when simply pressing the “Compile”...

> **[Slate Style crash the editor](https://forums.unrealengine.com/questions/22051/slate-style-crash-the-editor.html)**
>
> Hi! i’m trying to use my own style to build an HUD. I followed how it was done in the ShooterGame and StrategyGame. I got it working with some STextBlock and put a bunch of letter within a grid in the center of the screen, toggling it on and off...

I really hope they fix Slate up soon…

---

<div class="post-metadata">

**Author:** ![Dingo\_aus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dingo\_aus](https://forums.unrealengine.com/u/Dingo_aus)\
**Post date:** [May 10, 2014, 5:51am UTC](https://forums.unrealengine.com/t/slate-tutorial/732/38 "2014-05-10T05:51:38Z")

</div>

Does it matter which “Solution Configuration” Visual Studio is in when compiling? Does it impact the use in the Editor? If so, which is best to use?

---

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [May 10, 2014, 4:21pm UTC](https://forums.unrealengine.com/t/slate-tutorial/732/39 "2014-05-10T16:21:28Z")

</div>

> [@Dingo\_aus;36092](#):
>
> Does it matter which “Solution Configuration” Visual Studio is in when compiling? Does it impact the use in the Editor? If so, which is best to use?

Yes, Development Editor/Windows. Otherwise you will have some strange compilation errors related to generated files.

---

<div class="post-metadata">

**Author:** ![Akuthia](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Akuthia](https://forums.unrealengine.com/u/Akuthia)\
**Post date:** [May 30, 2014, 2:12pm UTC](https://forums.unrealengine.com/t/slate-tutorial/732/40 "2014-05-30T14:12:17Z")

</div>

Hey everyone, new UE4 dev here, and having a problem trying to get this to work. I think that my problem is that the last two files are being placed in \MyProject\Intermediate\ProjectFiles\ and not in \MyProject\Source\MyProject\ . Does anyone have an idea as to what I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0dc1700e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0dc1700e](https://forums.unrealengine.com/u/anonymous_user_0dc1700e)\
**Post date:** [June 28, 2014, 9:13pm UTC](https://forums.unrealengine.com/t/slate-tutorial/732/41 "2014-06-28T21:13:11Z")

</div>

> [@Akuthia;62681](#):
>
> Hey everyone, new UE4 dev here, and having a problem trying to get this to work. I think that my problem is that the last two files are being placed in \MyProject\Intermediate\ProjectFiles\ and not in \MyProject\Source\MyProject\ . Does anyone have an idea as to what I’m doing wrong?

That will do it. If the files are in the wrong directory the #include directives will break. By default Visual Studio puts new files in /MyProject/Intermediate/ProjectFiles/ when you “add new files” to your project.

[Previous page](https://forums.unrealengine.com/t/slate-tutorial/732.md?page=1)

[Next page](https://forums.unrealengine.com/t/slate-tutorial/732.md?page=3)
