Unreal UIs and C++: Slate

This is the final part of a mini-series on creating UIs in Unreal using UMG and Slate. Previously we discussed creating C++-based UserWidgets and creating new UMG classes.

Slate is the lowest-level of

Once again we will be implementing a simple button that contains an image and text, but this time we will see how to achieve the same result from Slate.

ExampleSlate.h

#pragma once

#include "CoreMinimal.h"

class SExampleSlate : public SCompoundWidget
{
	SLATE_BEGIN_ARGS(SStandardSlateWidget){}

	// See private declaration of OwnerHUD below.
	SLATE_ARGUMENT(TWeakObjectPtr<class AStandardHUD>, OwnerHUD)
 
	SLATE_END_ARGS()
 
public:
  // Required
	void Construct(const FArguments& InArgs);

	// Begin SWidget interface
	void OnArrangeChildren(const FGeometry& AllottedGeometry, FArrangedChildren& ArrangedChildren) const override;
	virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
	virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override;
	// End SWidget interface

 
private:
	TWeakObjectPtr<class AStandardHUD> OwnerHUD;
};

ExampleSlate.cpp


In this example there isn’t a lot of benefit from implementing the same behaviour in Slate over UMG. However for original, more complicated behaviour that cannot be broken down into pre-existing Slate widgets, creating a new Slate widget is your only option.

Conclusion

We saw that it’s