- Slate
- SlateCore
- Input Core (Some input fields, i.e. SNumericEntry, have input hooks and require this module)
- EditorStyle (Standard buttons, brushes, and font styles)
Defined in:
- SlateEditorStyle.h
- CoreStyle.h
Simple Style Usage
SNew(STextBlock)
+Text(TEXT("Simple Block of Text")
+TextStyle(FEditorStyle::Get(), "NormalText.Important")
The above style (NormalText.Important
) is defined in SlateEditorStyle.cpp at line 259.
Start with the Unreal Documentation walk-through for hooking in a Details Customization.
Grabbing the selected asset in the CustomizeDetails
:
// In header
private:
TWeakObjectPtr<class UMyAsset> MyAsset;
// Implementation
void FMyAssetDetails::CustomizeDetails(IDetailLayoutBuilder& detailLayout)
{
const TArray< TWeakObjectPtr<UObject> >& SelectedObjects = detailLayout.GetSelectedObjects();
for( int32 ObjectIndex = 0; !MyAsset.IsValid() && ObjectIndex < SelectedObjects.Num(); ++ObjectIndex )
{
const TWeakObjectPtr<UObject>& CurrentObject = SelectedObjects[ObjectIndex];
if ( CurrentObject.IsValid() )
{
MyAsset = Cast<UMyAsset>(CurrentObject.Get());
}
}
}
A typical use case for editor extensions is a custom editor window with some project-specific functionality. This is a two step process in Unreal:
- Creation of a Compound Widget (
SCompoundWidget
) - Embedding your compound widget into a container (i.e.
SWindow
,SDockTab
, etc)
Custom widgets extend from SCompoundWidget
and use a special class/syntax structure specific to Slate (what Unreal calls "Declarative Syntax"). You can create your source files for these in the typical way from the editor: Right-Click your editor project folder > New C++ Class > Choose Slate Widget.
This will create a header with the following code;
#pragma once
#include "CoreMinimal.h"
#include "Widgets/SCompoundWidget.h"
class SMyCustomWidget : public SCompoundWidget
{
public:
SLATE_BEGIN_ARGS(SMyCustomWidget)
{}
SLATE_END_ARGS()
/** Constructs this widget with InArgs */
void Construct(const FArguments& InArgs);
};
This will compile fine, but doesn't play nice with Visual Studio intellisense unless you also include Widgets/DeclarativeSyntaxSupport.h
:
#include "CoreMinimal.h"
#include "Widgets/SCompoundWidget.h"
#include "Widgets/DeclarativeSyntaxSupport.h" // Not included in the base template!
// Rest of header
On the implementation side, you will see the standard Construct
method wrapped in two macros BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
/END_SLATE_FUNCTION_BUILD_OPTIMIZATION
. Keep any complex Slate construction syntax between these macros to keep the compiler from attempting to optimize it and kill your re-compile times.
Unreal uses code templates (.template text files) to generate new code files. These are located in the engine content folder:
[Unreal Engine Installation]\Engine\Content\Editor\Templates
. Edit these in any text editor (but, as always, don't save compile errors into your templates 💡).