Slate Tutorial

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.

#pragma once

#include "Slate.h"

class SMenu: public SCompoundWidget



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


	//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();

#include SMenu.h

// Constructor
void SMainMenu::Construct(const FArguments& InArgs)

//create slot on  overlay for Menu
			+ SOverlay::Slot()
			// create Menu widget


TSharedRef<SWidget> SMainMenu::MyMenu()
	FMenuBuilder MenuBuilder(true, NULL, TSharedPtr<FExtender>(), false, &FCoreStyle::Get());
			.OnClicked(this, &SMainMenu::StartBtnClicked)
			, FText::GetEmpty());

			, FText::GetEmpty());

			, FText::GetEmpty());

			, 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();



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

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 ?

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.

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.

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.

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 !

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.

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


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:

[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?

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



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:

I really hope they fix Slate up soon…

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.

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.

I apologize for this. I talked to a UE4 dev and I was mistaken about that, any build you would want to use is fine. I just tested the sources with 4.2.1 and everything worked in a debug build. I didn’t even change a single line of code other than the #includes in cpp files to match my project’s name.

Hi! Please tell me how Can i use custom cursor with slate?

Hey guys, Thanks so much for giving me a starting point with Slate. I went through the tutorial a few hours ago and noticed many of the things have changed with the 4.8 update.

I took the initiate and updated the tutorial so it works with 4.8 I tested all the code I put in and made sure everything works.