Skip to content

Instantly share code, notes, and snippets.

@eman41
Last active June 4, 2019 15:22
Show Gist options
  • Save eman41/b1221017070ca4d60adcebe2d8f1ca2a to your computer and use it in GitHub Desktop.
Save eman41/b1221017070ca4d60adcebe2d8f1ca2a to your computer and use it in GitHub Desktop.
A one stop list of requirements, notes, and samples for developing extensions to the Unreal Editor

Unreal Editor Styles

Required Modules

  • Slate
  • SlateCore
  • Input Core (Some input fields, i.e. SNumericEntry, have input hooks and require this module)

Optional Modules

  • EditorStyle (Standard buttons, brushes, and font styles)

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.

Details Customization

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

Custom Widgets & Editor Windows

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:

  1. Creation of a Compound Widget (SCompoundWidget)
  2. 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.

Editing Code Templates

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 💡).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment