Skip to content

Instantly share code, notes, and snippets.

@rtm223
Last active January 16, 2026 18:29
Show Gist options
  • Select an option

  • Save rtm223/b5fde2f18442fbded354be59a5023278 to your computer and use it in GitHub Desktop.

Select an option

Save rtm223/b5fde2f18442fbded354be59a5023278 to your computer and use it in GitHub Desktop.
UE5 component to provide editor ticking functionality to Blueprints
// The MIT License
// Copyright (c) Richard Meredith AB
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#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
}
URTMEditorTickComponent::URTMEditorTickComponent()
{
PrimaryComponentTick.bCanEverTick = true;
PrimaryComponentTick.bStartWithTickEnabled = true;
PrimaryComponentTick.TickGroup = TG_PrePhysics;
bTickInEditor = true;
bIsEditorOnly = true;
}
void URTMEditorTickComponent::BeginPlay()
{
Super::BeginPlay();
SetComponentTickEnabled(false);
}
void URTMEditorTickComponent::TickComponent(float deltaTime, ELevelTick tickType, FActorComponentTickFunction* thisTickFunction)
{
Super::TickComponent(deltaTime, tickType, thisTickFunction);
const bool canEditorTick = bAllowEditorTick
&& RTMEditorTickComponent_Statics::CVarTickInEditor.GetValueOnAnyThread()
&& GetWorld()
&& GetWorld()->WorldType != EWorldType::PIE;
if(canEditorTick)
{
OnEditorTick.Broadcast(deltaTime);
FEditorScriptExecutionGuard ScriptGuard;
K2_OnEditorTick.Broadcast(deltaTime);
}
}
// The MIT License
// Copyright (c) Richard Meredith AB
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "RTMEditorTickComponent.generated.h"
/* Simple component that will tick in editor and provide the owning Actor BP with an On Editor Tick event */
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent), HideCategories=("Sockets", "ComponentTick", "Activation", "Replication","AssetUserData","Navigation", "Tags"))
class RTMCOMMON_API URTMEditorTickComponent : public UActorComponent
{
GENERATED_BODY()
public:
URTMEditorTickComponent();
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEditorTickDelegate, float, deltaSeconds);
DECLARE_EVENT_OneParam(ThisClass, FOnEditorTickEvent, float deltaSeconds);
FOnEditorTickEvent OnEditorTick;
protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Editor")
bool bAllowEditorTick = true;
/* Produces a tick while in editor scenes
* Does NOT tick in PIE or packaged builds
* Can be suppressed globally using CVar 'rtm.Editor.AllowEditorTickComponent=false'
or per-instance using the 'Allow Editor Tick' checkbox on the component */
UPROPERTY(BlueprintAssignable, Category="Editor", meta=(DisplayName="On Editor Tick"))
FOnEditorTickDelegate K2_OnEditorTick;
virtual void BeginPlay() override;
virtual void TickComponent(float deltaTime, ELevelTick tickType, FActorComponentTickFunction* thisTickFunction) override;
private:
FTimerHandle TimerHandle;
};
@rtm223
Copy link
Author

rtm223 commented Sep 15, 2024

Editor Tick Component

Add this component to an Actor Blueprint and select its "On Editor Tick" event to receive events in editor preview windows

image

Works in both the BP viewport and in levels
UnrealEditor-Win64-DebugGame_kgPvOi5HcJ
EditorDuck2

Can be suppressed using CVar rtm.Editor.AllowEditorTickComponent=false (global) or unchecking the Allow Editor Tick checkbox (per instance)

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