Slate, Hello - Epic Wiki
# Slate, Hello
From Epic Wiki
Jump to: navigation, search
Hello Slate!
This tutorial assumes an intermediate understanding of C++ and event driven systems. It will give you a basic introduction to adding HUD capable of rendering Slate Widgets. In line with ancient tradition, the Slate Widget will render a text-box displaying the message "Hello, Slate!". Aside from the sources, there are a several steps involved in setting up a project that can handle Slate Widgets. Some things that may be glaringly obvious to someone with experience might be glazed over that aren't as obvious to someone just learning C.
# Contents
- 1 Creating a project
- 2 Creating the HUD and Widget files
- 3 Allow C++ Access to Slate API by Modifying Build File
- 4 Adding code to our HUD
- 5 Creating the content of our Widget
- 6 Set the Game Mode's HUD
- 7 Watching the result
- 8 Links and Further Reading
- 9 Change Log
# Creating a project
If you have not done so already the first thing to do is to create a blank C++ project. For the purpose of this tutorial, it is recommended that you have "Include Starter Content" unticked. This tutorial will use the project name HelloSlate, however you can call it anything of your own choosing as long as you're comfortable with making the appropriate changes to the provided source files. For beginners I would suggest that you do not diverge from the provided example.
# Creating the HUD and Widget files
Now the open the project. We will have to create four new c++ files:
- StandardHUD.h
- StandardHUD.cpp
- StandardSlateWidget.h
- StandardSlateWidget.cpp
To create the files, we suggest you use the UE Editor as follows.
Note: You can create these manually. As you might be aware of already, when you create .cpp and .h files manually, Unreal puts the files in the intermediate folder. Make sure your files are in the source folder like they should be.
# Create the HUD class
File --> New c++ Class --> On the Choose Parent Class list select "HUD" --> Click Next
Then name for this class will be : StandardHUD. Leave the path as it is (..../HelloSlate/Source/HelloSlate/). The files should look like: .../HelloSlate/Source/HelloSlate/StandardHUD.h and .cpp
Wait until the editor compiles the new files. It will open a Visual Studio instance.
Now you will see the HUD file (represents the h and cpp) in your Content Browser, under C++ Classes -> HelloSlate, next to the GameModeBase file.
# Create the Slate Widget class
Repeat the process and this time choose parent class "Slate Widget". The name of the class will be "StandardSlateWidget". After creating this class, you will not see it on the Content Browser.
As for v4.18, if you have any problem when Visual Studio opens due to some bugs while creating a new class, you can close all VS instances and go to "File -> Refresh Visual Studio Project". Another good way to continue is to go to "File -> Open Project" and reopen this project again.
Now open Visual Studio by going to "File -> Open Visual Studio" or double clicking the new Standard HUD file on the content browser.
How the new files look in the project explorer
# Allow C++ Access to Slate API by Modifying Build File
Open the HelloSlate.Build.cs file (typically located in $Projectfolder/$Projectname/Source/$Projectname) and modify it to allow Slate.
The contents of this file has changed since 4.8. In v4.18 you will find a commented line saying: Uncomment if you are using Slate UI
Just uncomment the following line: