Skip to content

Instantly share code, notes, and snippets.

View rtm223's full-sized avatar

Richard Meredith rtm223

View GitHub Profile
@rtm223
rtm223 / MaterialNodeSnipped.cpp
Created September 20, 2025 10:58
Creating a standalone Material Function Expression Node Widget
// Minimum code for standing up an SGraphNodeMaterialBase for a material fucntion
// Note, the various UObjects created here (material etc.) are probably not being kept alive and may be GC'd so will want strong refs if you want to keep your widget alive
UMaterial* material = NewObject<UMaterial>(outer, NAME_None, RF_Standalone | RF_Public);
auto* expression_materialFunction = Cast<UMaterialExpressionMaterialFunctionCall>(UMaterialEditingLibrary::CreateMaterialExpressionEx(material, nullptr, UMaterialExpressionMaterialFunctionCall::StaticClass(), materialFunction));
UMaterialGraph* graph = NewObject<UMaterialGraph>();
graph->Schema = UMaterialGraphSchema::StaticClass();
UMaterialGraphNode* node = graph->AddExpression(expression_materialFunction, true);
TSharedRef<SGraphNodeMaterialBase> nodeWidget = SNew(SGraphNodeMaterialBase, node);
@rtm223
rtm223 / RTMEditorTickComponent.cpp
Last active September 15, 2024 08:01
UE5 component to provide editor ticking functionality to Blueprints
#include "Components/RTMEditorTickComponent.h"
namespace RTMEditorTickComponent_Statics
{
#if RTMCOMMON_ENABLE_DEBUG_DISPLAY
static TAutoConsoleVariable<bool> CVarTickInEditor(
TEXT("rtm.Editor.AllowEditorTickComponent"),
true,
TEXT("Enables Editor Tick Components globally"));
#endif
@rtm223
rtm223 / RTMHUDBase.cpp
Created June 12, 2024 18:42
Base Class Unreal HUD that can hide all widgets via the ShowHUD console command and when you enter simulate
#include "UI/HUD/RTMHUDBase.h"
#include "Engine/LocalPlayer.h"
#include "GameFramework/PlayerController.h"
#include "Widgets/SViewport.h"
namespace RTMHUDBaseStatics
{
SWidget* FindWidgetByTypeRecursive(SWidget* root, FName widgetType)
{
SWidget* ret = nullptr;
@rtm223
rtm223 / RTMCursorReceiverWidget.cpp
Created October 10, 2022 15:13
Cursor Receiver Widget
// Copyright (c) Richard Meredith AB. All Rights Reserved
#include "UI/UMG/RTMCursorReceiverWidget.h"
#include "UI/Slate/SRTMCursorReceiver.h"
#define LOCTEXT_NAMESPACE "RTM"
TSharedRef<SWidget> URTMCursorReceiverWidget::RebuildWidget()
{
Receiver = SNew(SRTMCursorReceiver)
@rtm223
rtm223 / RTMNavBoundaryComponent.cpp
Last active November 9, 2022 03:19
UE4/5 navmesh helper to detect Navmesh boundaries
#include "RTMNavBoundaryComponent.h"
#include "NavigationSystem.h"
#include "NavMesh/RecastHelpers.h"
#include "NavMesh/RecastNavMesh.h"
#include "Navmesh/Public/Detour/DetourNavMesh.h"
const FRTMNavBoundary FRTMNavBoundary::EMPTY = {{}};
DECLARE_LOG_CATEGORY_CLASS(LogRTMNavBoundaryComponent, Log, All)
@rtm223
rtm223 / RTMEnumOperators.h
Last active September 1, 2022 22:47
cpp Enum Operators (for class enums)
// Copyright (c) Richard Meredith AB. All Rights Reserved
// ReSharper disable once CppMissingIncludeGuard
//
// Adds all(?) overloads for Scoped Enumerations (Enum Classes).
// Multiple inclusions allowed. #define TEnum (and any options) for each
//
// Usage:
// namespace MyNameSpace // namespace optional
// {
// enum class EMyEnum : uint8
@rtm223
rtm223 / RTMBlueprintCompiler_MustImplementFunction.cpp
Last active July 15, 2024 10:23
UFUNCTION(meta=(MustImplementInBlueprint))
#include "RTMBlueprintCompiler_MustImplementFunction.h"
#define LOCTEXT_NAMESPACE "RTMValidator_MustImplementFunction"
bool URTMBlueprintCompiler_MustImplementFunction::CanValidateBlueprint(const UBlueprint* blueprint) const
{
switch(blueprint->BlueprintType)
{
case BPTYPE_Normal:
case BPTYPE_Const: