<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/">
  <channel>
    <title>lifecycle on stillcooking.dev</title>
    <link>https://stillcooking.dev/en/tags/lifecycle/</link>
    <description>Personal portfolio and technical notes</description>
    <generator>Hugo</generator>
    <language>en-US</language>
    
    <copyright>© 2026 stillcooking.dev — CC BY 4.0, https://creativecommons.org/licenses/by/4.0/</copyright>
    <lastBuildDate>Thu, 30 Jul 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://stillcooking.dev/en/tags/lifecycle/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>A tickable UObject — how to build one, what to keep in mind</title>
      <link>https://stillcooking.dev/en/topics/unreal-engine/gameplay-framework/tickable-uobject/</link>
      <pubDate>Thu, 30 Jul 2026 00:00:00 +0000</pubDate>
      
      <guid isPermaLink="true">https://stillcooking.dev/en/topics/unreal-engine/gameplay-framework/tickable-uobject/</guid>
      <description>How to build a base class for a ticking UObject in a UE project: the design decisions that matter, with the complete class available in StillCooking_Tools.</description>
      <content:encoded><![CDATA[<p>A <code>UObject</code> does not tick. It has no <code>PrimaryActorTick</code>, it belongs to no tick group, and the engine has no reason to visit it every frame. The standard answer is multiple inheritance: <code>UObject</code> plus <code>FTickableGameObject</code>. The catch is that inheritance alone does not give you a tick, only registration. Everything that determines <em>whether</em>, <em>when</em>, and <em>for how long</em> the object actually ticks is still yours to set up.</p>
<h2 id="what-ftickablegameobject-is">What <code>FTickableGameObject</code> is</h2>
<p><code>FTickableGameObject</code> is a plain C++ class from <code>Tickable.h</code> that you inherit from alongside <code>UObject</code>. Its constructor adds <code>this</code> to a pending queue (<code>Tickable.cpp:133-145</code>), and the object only moves into the real array at the next tick pass (<code>Tickable.cpp:67-95</code>). The destructor removes it from that array (<code>Tickable.cpp:147-152</code>), and the engine walks the array once per frame (<code>Tickable.cpp:167-208</code>). This is a separate track running alongside the <code>FTickFunction</code> machinery that actors and components use. It is not part of it.</p>
<p>The upside is that the object does not have to be in a world, does not have to be spawned, and has no transform. The price is that it also gets none of what the other track gives actors: no tick groups, no <code>AddTickPrerequisiteActor</code>, no <code>TickInterval</code>. The entire class declaration (<code>Tickable.h:134-210</code>) does not contain a single one of them. You either give up all three or build them by hand.</p>
<p>For an object tied to a world, the call sits in <code>UWorld::Tick</code> (<code>LevelTick.cpp:1792</code>), after <code>TG_PostPhysics</code> (<code>LevelTick.cpp:1749</code>) but before <code>TG_PostUpdateWork</code> (<code>LevelTick.cpp:1848</code>). An actor ticking in <code>TG_PostUpdateWork</code> sees the state this tick has already produced. An object with no world lands somewhere else: it ticks only after the loop over all worlds. The engine says so outright in the comment on the method (<code>Tickable.h:183</code>), and the call itself sits in <code>GameEngine.cpp:1947</code>.</p>
<h2 id="when-to-reach-for-this-and-when-not-to">When to reach for this, and when not to</h2>
<p><strong>Does this have to be an actor?</strong> If the object needs a transform, collision, replication, placement in a level, or tick groups, the answer is “actor” and the rest of this post does not apply. None of those can be bolted onto <code>FTickableGameObject</code>.</p>
<p><strong>Is the logic per-frame or event-driven?</strong> If it comes down to “in three seconds” or “every half second” and nothing in between, that is <code>FTimerManager</code>, not a tick. Polling state sixty times a second to respond once is a cost with no return.</p>
<p><strong>Should the object live exactly as long as the world?</strong> If so, the right answer is almost always <code>UTickableWorldSubsystem</code>: a ready, tested lifecycle, without a single line of what I describe below. Your own base class earns its place when you need <strong>multiple instances</strong> (a subsystem is one instance per class per owner by definition), or when a designer is meant to create subclasses in Blueprint, which a subsystem cannot do.</p>
<div class="callout callout--insight">
  <div class="callout__title">Insight</div>
  <code>UTickableWorldSubsystem</code> is the best possible source on this: it is Epic&rsquo;s own implementation of the pattern. The whole class fits in <code>WorldSubsystem.cpp:97-160</code>.
</div>

<h2 id="decision-one-when-you-register">Decision one: when you register</h2>
<p>The default answer: <strong>in the constructor</strong>. Inheritance is enough. The base constructor runs on its own, the object lands in the registry, no extra code.</p>
<p>And that is exactly what you must not do. The constructor documentation says so outright:</p>
<blockquote>
<p>If this is something like a UObject that could be created on a different thread (like for async loading), construct with a Never tick type and enable tick later.</p>
<p>— <code>Tickable.h:147</code> (UE 5.7)</p>
</blockquote>
<p>The base constructor in full:</p>
<div class="highlight" data-lang="cpp">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="c1">// UE 5.7 — Tickable.cpp:133-145
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="n">FTickableGameObject</span><span class="o">::</span><span class="n">FTickableGameObject</span><span class="p">(</span><span class="n">ETickableTickType</span> <span class="n">StartingTickType</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">StartingTickType</span> <span class="o">!=</span> <span class="n">ETickableTickType</span><span class="o">::</span><span class="n">Never</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="c1">// It is only safe to create tickable game objects on the game thread, as otherwise there is a race condition between object initialize and the game thread tick
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>        <span class="c1">// If you hit this ensure, change the constructor to use FTickableGameObject(ETickableTickType::Never) and call SetTickableTickType after initialization
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>        <span class="n">ensure</span><span class="p">(</span><span class="n">IsInGameThread</span><span class="p">());</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="c1">// Queue for creation, this can get called very early in startup
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>        <span class="n">FTickableStatics</span><span class="o">&amp;</span> <span class="n">Statics</span> <span class="o">=</span> <span class="n">GetStatics</span><span class="p">();</span>
</span></span><span class="line"><span class="cl">        <span class="n">Statics</span><span class="p">.</span><span class="n">QueueTickableObjectForAdd</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="n">StartingTickType</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></div></div>
<p>The base constructor runs <strong>before</strong> the body of the derived class constructor, <strong>before</strong> the archetype and Blueprint-class defaults are applied over the native ones, and <strong>before</strong> the owner has a chance to configure anything. Defaults are not applied until <code>FObjectInitializer::PostConstructInit</code> (<code>UObjectGlobals.cpp:4239</code>), the copy itself in <code>UObjectGlobals.cpp:4350</code>, and <code>PostInitProperties</code> runs later still (<code>UObjectGlobals.cpp:4427</code>) — all three after the C++ constructor chain. The next tick pass will call <code>GetTickableTickType()</code>, and then <code>Tick()</code>, on a half-configured object. On top of that, the CDO registers along with the instances, because the <code>FTickableGameObject</code> constructor does not check <code>IsTemplate()</code> or anything of the sort (<code>Tickable.cpp:133-145</code>).</p>
<p>The correct answer is to construct with an explicit “do not tick” and enable ticking later:</p>
<div class="highlight" data-lang="cpp">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="n">UTickableObject</span><span class="o">::</span><span class="n">UTickableObject</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="o">:</span> <span class="n">FTickableGameObject</span><span class="p">(</span><span class="n">ETickableTickType</span><span class="o">::</span><span class="n">Never</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="c1">// Deliberately empty. Registering for tick here is exactly what Tickable.h forbids.
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="p">}</span></span></span></code></pre></div></div>
<h2 id="decision-two-when-you-unregister">Decision two: when you unregister</h2>
<p>The default answer: <strong>in the destructor</strong>. And again it is too late. A <code>UObject</code> destructor runs long after the object stopped being useful, and in the meantime the engine is free to tick it.</p>
<p>The right place is an explicit method called by the owner, plus a hard gate in <code>BeginDestroy()</code> as the last line of defense. The tick queries themselves are gates too, each in its own place:</p>
<div class="highlight" data-lang="cpp">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="n">ETickableTickType</span> <span class="n">UTickableObject</span><span class="o">::</span><span class="n">GetTickableTickType</span><span class="p">()</span> <span class="k">const</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="c1">// Never for the CDO and before Initialize: the object stays out of the tickable
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="c1">// array entirely instead of sitting in it and being polled every frame.
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="k">return</span> <span class="p">(</span><span class="n">IsTemplate</span><span class="p">()</span> <span class="o">||</span> <span class="o">!</span><span class="n">bInitialized</span><span class="p">)</span> <span class="o">?</span> <span class="n">ETickableTickType</span><span class="o">::</span><span class="nl">Never</span> <span class="p">:</span> <span class="n">ETickableTickType</span><span class="o">::</span><span class="n">Conditional</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kt">bool</span> <span class="n">UTickableObject</span><span class="o">::</span><span class="n">IsTickable</span><span class="p">()</span> <span class="k">const</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">bInitialized</span> <span class="o">&amp;&amp;</span> <span class="n">bTickEnabled</span> <span class="o">&amp;&amp;</span> <span class="n">CachedWorld</span><span class="p">.</span><span class="n">IsValid</span><span class="p">()</span> <span class="o">&amp;&amp;</span> <span class="n">IsValidChecked</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></div></div>
<p>The split between these two methods is deliberate. <code>IsTemplate()</code> belongs in <code>GetTickableTickType</code>, not in <code>IsTickable</code>: that way the CDO never enters the array at all, instead of sitting in it and answering “no” every frame. <code>IsTickable</code> is left for the conditions that genuinely change over the object&rsquo;s lifetime.</p>
<div class="callout callout--note">
  <div class="callout__title">Note</div>
  <p>Implement <code>DisableTick()</code> as <code>SetTickableTickType(ETickableTickType::Never)</code>, a real removal from the array, rather than as a flag read in <code>IsTickable</code>. It comes at one cost worth remembering: re-enabling takes effect from the next tick pass, because <code>SetTickableTickType</code> adds the object to a pending queue (<code>Tickable.cpp:59-63</code>) that the engine drains at the start of the following pass (<code>Tickable.cpp:67-95</code>). An object enabled from inside <code>Tick()</code> does not tick a second time in the same frame.</p>
<div class="highlight" data-lang="cpp">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="c1">// UE 5.7 — Tickable.cpp:59-63, indentation reduced (branch for an object not yet in the array)
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="k">else</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="c1">// Add to the pending list (which could override previous request), this will apply it next frame
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="n">NewTickableObjects</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="n">InTickable</span><span class="p">,</span> <span class="n">NewTickType</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></div></div>
</div>

<h2 id="decision-three-which-world-you-belong-to">Decision three: which world you belong to</h2>
<p>The default answer: <strong>none</strong>. Left unoverridden, <code>GetTickableGameObjectWorld()</code> returns <code>nullptr</code> (<code>Tickable.h:187-190</code>), and the object ticks in the global pass that follows all the worlds — knowing nothing about pause, nothing about PIE, nothing about the moment its world stops existing.</p>
<p>Overriding that method is cheap and handles all three at once:</p>
<div class="highlight" data-lang="cpp">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="n">UWorld</span><span class="o">*</span> <span class="n">UTickableObject</span><span class="o">::</span><span class="n">GetTickableGameObjectWorld</span><span class="p">()</span> <span class="k">const</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">CachedWorld</span><span class="p">.</span><span class="n">Get</span><span class="p">();</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></div></div>
<p>I resolve the world once, in <code>Initialize()</code>, and hold it in a <code>TWeakObjectPtr&lt;UWorld&gt;</code>. Plain <code>GetWorld()</code> is enough: the default <code>UObject::GetWorld()</code> implementation walks the Outer chain (<code>Obj.cpp:1145-1150</code>), so an object created with a sensible Outer finds its world with no help at all.</p>
<p>Here is the trap I ran into. Once the world is gone, <code>CachedWorld.Get()</code> starts returning <code>nullptr</code>. You would expect that to be the end of the tick. The opposite is true. The gate in the engine reads <code>GetTickableGameObjectWorld() == World</code> (<code>Tickable.cpp:189</code>), and <code>TickObjects</code> is <strong>also</strong> called with <code>World == nullptr</code>, precisely for objects with no world (<code>GameEngine.cpp:1947</code>). The comparison <code>nullptr == nullptr</code> passes. The object does not stop ticking. It quietly <strong>migrates</strong> from its own world&rsquo;s tick to the global engine pass and keeps going.</p>
<p>The whole condition in the engine loop:</p>
<div class="highlight" data-lang="cpp">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="c1">// UE 5.7 — Tickable.cpp:186-189 (indentation reduced)
</span></span></span><span class="line"><span class="cl"><span class="c1">// If it is tickable and in this world
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="k">if</span> <span class="p">(</span><span class="n">TickableObject</span><span class="o">-&gt;</span><span class="n">IsAllowedToTick</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="o">&amp;&amp;</span> <span class="p">((</span><span class="n">TickableEntry</span><span class="p">.</span><span class="n">TickType</span> <span class="o">==</span> <span class="n">ETickableTickType</span><span class="o">::</span><span class="n">Always</span><span class="p">)</span> <span class="o">||</span> <span class="n">TickableObject</span><span class="o">-&gt;</span><span class="n">IsTickable</span><span class="p">())</span>
</span></span><span class="line"><span class="cl">    <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="n">TickableObject</span><span class="o">-&gt;</span><span class="n">GetTickableGameObjectWorld</span><span class="p">()</span> <span class="o">==</span> <span class="n">World</span><span class="p">))</span></span></span></code></pre></div></div>
<p>Closing this takes two things at once: the <code>CachedWorld.IsValid()</code> condition in <code>IsTickable()</code>, and a subscription to world cleanup, so that the object shuts itself down instead of just no longer being polled.</p>
<div class="highlight" data-lang="cpp">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="kt">void</span> <span class="n">UTickableObject</span><span class="o">::</span><span class="n">HandleWorldCleanup</span><span class="p">(</span><span class="n">UWorld</span><span class="o">*</span> <span class="n">World</span><span class="p">,</span> <span class="kt">bool</span> <span class="n">bSessionEnded</span><span class="p">,</span> <span class="kt">bool</span> <span class="n">bCleanupResources</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">World</span> <span class="o">==</span> <span class="n">CachedWorld</span><span class="p">.</span><span class="n">Get</span><span class="p">())</span>
</span></span><span class="line"><span class="cl">    <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="n">Shutdown</span><span class="p">();</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></div></div>
<p>The delegate is <code>FWorldDelegates::OnWorldCleanup</code>, hooked up in <code>Initialize()</code> and removed in <code>Shutdown()</code>. Unregistering from inside your own broadcast is safe: Unreal&rsquo;s multicast delegates defer compacting the list until the call finishes (<code>MulticastDelegateBase.h:380-390</code>).</p>
<h2 id="decision-four-who-cleans-up">Decision four: who cleans up</h2>
<p>The default answer: <strong>nobody</strong>. A <code>UObject</code> with no <code>UPROPERTY</code> reference is collected at the next GC, and that is the correct behavior. It just has to be handled deliberately, instead of discovered halfway through a session when the object is already gone.</p>
<p>The reflex is <code>AddToRoot()</code>. That is not lifetime management; it is turning GC off for this object, with a manual <code>RemoveFromRoot()</code> as the only way out. The object survives a map change and everything else.</p>
<p>A sensible contract is simpler and puts both obligations on the owner: the object lives in a <code>UPROPERTY(TObjectPtr&lt;&gt;)</code>, and <code>Shutdown()</code> runs before that reference is dropped.</p>
<div class="callout callout--warning">
  <div class="callout__title">Warning</div>
  <p><strong>Teardown does not belong in <code>BeginDestroy()</code>.</strong> It is tempting to hook it there — it looks like a fair way to close the lifecycle, one that saves a forgetful owner. It blows up Blueprint subclasses.</p>
<p>On the GC path the object already has the <code>Unreachable</code> flag set (<code>GarbageCollection.cpp:5264</code>, before <code>ConditionalBeginDestroy</code> is even called in <code>GarbageCollection.cpp:6155</code>), and a <code>BlueprintNativeEvent</code> overridden in Blueprint dispatches through <code>UObject::ProcessEvent</code>, which opens with <code>checkf(!IsUnreachable(), ...)</code> (<code>ScriptCore.cpp:2015-2020</code>).</p>
<p>The result: the first Blueprint subclass to implement the teardown event crashes the editor during an ordinary garbage collection. In a Shipping build the <code>check</code> is gone, so instead of a crash you get a silently skipped teardown — behavior that differs by build configuration, which is harder still to catch.</p>

</div>

<p>So <code>BeginDestroy()</code> does exactly as much as it has to and not an ounce more: it removes the delegate (a plain <code>Remove</code>, no dispatch into Blueprint), kills the tick, and reports that the owner never called <code>Shutdown()</code>.</p>
<div class="highlight" data-lang="cpp">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="kt">void</span> <span class="n">UTickableObject</span><span class="o">::</span><span class="n">BeginDestroy</span><span class="p">()</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="n">FWorldDelegates</span><span class="o">::</span><span class="n">OnWorldCleanup</span><span class="p">.</span><span class="n">Remove</span><span class="p">(</span><span class="n">WorldCleanupHandle</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="n">WorldCleanupHandle</span><span class="p">.</span><span class="n">Reset</span><span class="p">();</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">SetTickableTickType</span><span class="p">(</span><span class="n">ETickableTickType</span><span class="o">::</span><span class="n">Never</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="n">bTickEnabled</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">ensureAlwaysMsgf</span><span class="p">(</span><span class="o">!</span><span class="n">bInitialized</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="n">TEXT</span><span class="p">(</span><span class="s">&#34;%s: destroyed while still initialized - the owner never called Shutdown().&#34;</span><span class="p">),</span> <span class="o">*</span><span class="n">GetName</span><span class="p">());</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">Super</span><span class="o">::</span><span class="n">BeginDestroy</span><span class="p">();</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></div></div>
<p><code>ensureAlwaysMsgf</code>, not <code>ensureMsgf</code>: a plain <code>ensure</code> fires once per callsite per process. The <code>bEnsureHasExecuted</code> flag is keyed by a hash of <code>__FILE__</code> and <code>__LINE__</code>, and the <code>Always</code> variant skips that filter (<code>AssertionMacros.h:440-448</code>). The first leaked object would silence the diagnostic for every one after it.</p>
<p>Epic does the same in <code>UTickableWorldSubsystem::BeginDestroy</code> (<code>WorldSubsystem.cpp:154-159</code>): it does not call <code>Deinitialize</code> from there — and now the reason is clear. Two differences from the listing above are deliberate: Epic leaves a plain <code>ensureMsgf</code> there (<code>WorldSubsystem.cpp:158</code>) and calls <code>Super::BeginDestroy()</code> first (<code>WorldSubsystem.cpp:156</code>).</p>
<h2 id="the-whole-class">The whole class</h2>
<p>The complete implementation ships in <a href="/en/products/stillcooking-tools/">StillCooking_Tools</a> as
<code>USCTickableObject</code> — a free, MIT-licensed plugin distributed as C++ source
(<a href="https://github.com/StillCooking/StillCooking_Tools" data-external rel="noopener" target="_blank">GitHub</a>), module <code>StillCookingCore</code>, header
<code>Objects/SCTickableObject.h</code>. It is the class from this post, developed further: on top of the four
decisions above it adds an explicit tick intent that <code>Initialize()</code> applies, the <code>bTickWhenPaused</code>
and <code>bTickInEditor</code> gates, and a <code>protected</code> engine-facing interface with <code>IsTickable()</code> marked
<code>final</code>.</p>
<ul>
<li><a href="/en/products/stillcooking-tools/docs/reference/tickable-object/">Reference: <code>USCTickableObject</code></a> —
functions, properties, events and the messages it logs.</li>
<li><a href="/en/products/stillcooking-tools/docs/concepts/lifecycle/">Lifecycle</a> — the ownership contract and
what happens when the owner forgets <code>Shutdown()</code>.</li>
</ul>
<h2 id="checklist">Checklist</h2>
<p>Five things to check in your own class:</p>
<ol>
<li>The constructor calls <code>FTickableGameObject(ETickableTickType::Never)</code> and does <strong>nothing else</strong> tick-related.</li>
<li><code>GetTickableTickType()</code> returns <code>Never</code> for <code>IsTemplate()</code> and for the pre-initialization state, so the CDO never enters the array.</li>
<li><code>GetTickableGameObjectWorld()</code> returns a real world, and <code>IsTickable()</code> checks whether that world is still alive.</li>
<li>There is an explicit shutdown method called by the owner, plus a world-cleanup subscription for the case where the world goes first.</li>
<li><code>BeginDestroy()</code> kills the tick and reports the problem, but does <strong>not</strong> run subclass teardown.</li>
</ol>
]]></content:encoded>
      
    </item>
    
    <item>
      <title>A dispatcher broadcast from inside a handler does not see later bindings</title>
      <link>https://stillcooking.dev/en/topics/unreal-engine/gameplay-framework/event-dispatcher-bind-order/</link>
      <pubDate>Tue, 28 Jul 2026 00:00:00 +0000</pubDate>
      
      <guid isPermaLink="true">https://stillcooking.dev/en/topics/unreal-engine/gameplay-framework/event-dispatcher-bind-order/</guid>
      <description>A Blueprint Event Dispatcher calls its bindings in registration order unless removals have reordered the list: ProcessMulticastDelegate iterates a copy from front to back. When one handler broadcasts another dispatcher, only bindings already registered with that dispatcher are included. Bindings added by later handlers do not exist yet. In this example, registration order follows from the lifecycle phases in which the Bind Event to&amp;hellip; nodes run across different Blueprints.</description>
      <content:encoded><![CDATA[<p>The dispatcher <code>OnDelegate_1</code> has two bindings. The first handler broadcasts <code>OnDelegate_2</code> while it runs. The second handler binds <code>CustomEvent_3</code> to <code>OnDelegate_2</code>, but by then the broadcast is already over.</p>
<p>The cause is not a race condition. A dispatcher broadcast is a synchronous loop over an array: one thread, one frame, the same result every time. The call order of the bindings is deterministic, and relying on it is legitimate, provided you know where that order comes from and what changes it. It comes from the lifecycle phase in which each <code>Bind Event to…</code> node ran.</p>
<h2 id="the-test-setup">The test setup</h2>
<p>UE 5.7, pure Blueprint, two separate Blueprints. <code>BP_GameInstance_Test</code> owns both dispatchers and <code>CustomEvent_1</code>, which is bound in <code>Init</code>:</p>
<figure class="bp-embed">
  <div class="bp-embed__canvas" data-bp-src="/blueprints/dispatcher-order-a-gameinstance.txt" data-bp-height="400"></div>
  <noscript>
    <p class="bp-embed__fallback">Viewing the graph requires JavaScript.</p>
    <a class="bp-embed__download" href="/blueprints/dispatcher-order-a-gameinstance.txt" download>Download Blueprint graph (.txt)</a>
  </noscript><figcaption class="bp-embed__caption">BP_GameInstance_Test: Init binds CustomEvent_1 to OnDelegate_1. CustomEvent_1 itself logs [1] and then broadcasts OnDelegate_2.</figcaption></figure>
<p>The actor <code>BP_DispatcherTest</code> binds to the same <code>OnDelegate_1</code> in <code>BeginPlay</code>, and its handler is what creates the binding on <code>OnDelegate_2</code>:</p>
<figure class="bp-embed">
  <div class="bp-embed__canvas" data-bp-src="/blueprints/dispatcher-order-a-actor.txt" data-bp-height="900"></div>
  <noscript>
    <p class="bp-embed__fallback">Viewing the graph requires JavaScript.</p>
    <a class="bp-embed__download" href="/blueprints/dispatcher-order-a-actor.txt" download>Download Blueprint graph (.txt)</a>
  </noscript><figcaption class="bp-embed__caption">BP_DispatcherTest: BeginPlay binds CustomEvent_2 to OnDelegate_1. CustomEvent_2 logs [2] and only then binds CustomEvent_3 (log [3]) to OnDelegate_2.</figcaption></figure>
<p>A key press in the Level Blueprint fires the broadcast. After calling <code>OnDelegate_1</code>, the graph logs <code>[END TEST]</code>. That marker marks the end of the synchronous execution triggered by the key press, and it makes the log comparisons further down readable:</p>
<figure class="bp-embed">
  <div class="bp-embed__canvas" data-bp-src="/blueprints/dispatcher-order-a-levelbp.txt" data-bp-height="420"></div>
  <noscript>
    <p class="bp-embed__fallback">Viewing the graph requires JavaScript.</p>
    <a class="bp-embed__download" href="/blueprints/dispatcher-order-a-levelbp.txt" download>Download Blueprint graph (.txt)</a>
  </noscript><figcaption class="bp-embed__caption">LVL_DispatcherTest: the key press broadcasts OnDelegate_1 on the GameInstance, then logs [END TEST].</figcaption></figure>
<p>One key press, and the Output Log shows:</p>
<div class="highlight" data-lang="log">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><pre tabindex="0" class="ue-log"><code><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[1]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[2]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[END TEST]</span>
</span></code></pre>
</div>
<p><code>[3]</code> never appears. A breakpoint on <code>CustomEvent_3</code> is never hit. There is no compile error, no red node, and no warning. From the engine’s point of view nothing went wrong: the dispatcher called everything that was registered at the moment of the call, and <code>CustomEvent_3</code> was not registered then.</p>
<h2 id="this-is-not-a-race-condition">This is not a race condition</h2>
<p>The symptom suggests a race condition: the binding and the broadcast are competing, and the broadcast wins. That explanation is false and sends the diagnosis in the wrong direction.</p>
<p>Nothing here is racing anything. When <code>CustomEvent_1</code> broadcasts <code>OnDelegate_2</code>, <code>CustomEvent_2</code> has not started running yet. Not because it was too slow, but because it comes later in program order. Run the same project a hundred times and it behaves identically a hundred times.</p>
<p>The distinction has practical consequences. A race condition is something you look for in timing and try to fix with a delay added just in case. A delay does work here, but not for the reason that hypothesis suggests: it doesn&rsquo;t give another thread time to catch up, it moves the <code>OnDelegate_2</code> broadcast past the end of the entire <code>OnDelegate_1</code> handler list. It is worth knowing which of the two you are buying.</p>
<h2 id="proving-the-order-is-deterministic">Proving the order is deterministic</h2>
<p>The setup above shows where the invisible order comes from, but it mixes two variables at once. One Blueprint is enough to isolate it: all three custom events on <code>BP_GameInstance_Test</code>, both bindings to <code>OnDelegate_1</code> on a single exec wire in <code>Init</code>, no actor and no <code>BeginPlay</code>.</p>
<figure class="bp-embed">
  <div class="bp-embed__canvas" data-bp-src="/blueprints/dispatcher-order-b-first.txt" data-bp-height="1080"></div>
  <noscript>
    <p class="bp-embed__fallback">Viewing the graph requires JavaScript.</p>
    <a class="bp-embed__download" href="/blueprints/dispatcher-order-b-first.txt" download>Download Blueprint graph (.txt)</a>
  </noscript><figcaption class="bp-embed__caption">Arrangement one: in Init, CustomEvent_1 is bound first, then CustomEvent_2.</figcaption></figure>
<div class="highlight" data-lang="log">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><pre tabindex="0" class="ue-log"><code><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[1]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[2]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[END TEST]</span>
</span></code></pre>
</div>
<p>Now the only change in the entire project: the exec wire between the two <code>Bind Event to OnDelegate_1</code> nodes is swapped. The nodes, the events, their contents, and the Level Blueprint stay untouched.</p>
<figure class="bp-embed">
  <div class="bp-embed__canvas" data-bp-src="/blueprints/dispatcher-order-b-swapped.txt" data-bp-height="1080"></div>
  <noscript>
    <p class="bp-embed__fallback">Viewing the graph requires JavaScript.</p>
    <a class="bp-embed__download" href="/blueprints/dispatcher-order-b-swapped.txt" download>Download Blueprint graph (.txt)</a>
  </noscript><figcaption class="bp-embed__caption">Arrangement two: identical contents, the two Bind Event nodes in reverse order.</figcaption></figure>
<div class="highlight" data-lang="log">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><pre tabindex="0" class="ue-log"><code><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[2]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[1]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[3]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[END TEST]</span>
</span></code></pre>
</div>
<p><code>CustomEvent_2</code> ran first, bound <code>CustomEvent_3</code> to <code>OnDelegate_2</code>, and only then did <code>CustomEvent_1</code> broadcast that dispatcher. Reordering two nodes on an exec wire changed the result predictably and repeatably. The result follows directly from the order of execution: in one arrangement, registration happens after the broadcast; in the other, it happens before it.</p>
<div class="callout callout--warning">
  <div class="callout__title">Warning</div>
  When you repeat this test, press the key <strong>once per run</strong> and restart PIE between arrangements. A second press in arrangement one does log <code>[3]</code>, because the binding that <code>CustomEvent_2</code> created during the first broadcast is still there. That looks like instability, but it is leftover state from the previous call.
</div>

<h2 id="where-the-order-comes-from">Where the order comes from</h2>
<p>A Blueprint dispatcher is an <code>FMulticastScriptDelegate</code>, and its broadcast lives in <code>ScriptDelegates.h:917</code> (5.7):</p>
<div class="highlight" data-lang="cpp">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="k">if</span><span class="p">(</span> <span class="n">InvocationList</span><span class="p">.</span><span class="n">Num</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="c1">// Create a copy of the invocation list, just in case the list is modified by one of the callbacks during the broadcast
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="k">typedef</span> <span class="n">TArray</span><span class="o">&lt;</span> <span class="n">UnicastDelegateType</span><span class="p">,</span> <span class="n">TInlineAllocator</span><span class="o">&lt;</span> <span class="mi">4</span> <span class="o">&gt;</span> <span class="o">&gt;</span> <span class="n">FInlineInvocationList</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="n">FInlineInvocationList</span> <span class="n">InvocationListCopy</span> <span class="o">=</span> <span class="n">FInlineInvocationList</span><span class="p">(</span><span class="n">InvocationList</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1">// Invoke each bound function
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="k">for</span><span class="p">(</span> <span class="k">typename</span> <span class="n">FInlineInvocationList</span><span class="o">::</span><span class="n">TConstIterator</span> <span class="n">FunctionIt</span><span class="p">(</span> <span class="n">InvocationListCopy</span> <span class="p">);</span> <span class="n">FunctionIt</span><span class="p">;</span> <span class="o">++</span><span class="n">FunctionIt</span> <span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">if</span><span class="p">(</span> <span class="n">FunctionIt</span><span class="o">-&gt;</span><span class="n">IsBound</span><span class="p">()</span> <span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="n">FunctionIt</span><span class="o">-&gt;</span><span class="k">template</span> <span class="n">ProcessDelegate</span><span class="o">&lt;</span><span class="n">UObjectTemplate</span><span class="o">&gt;</span><span class="p">(</span><span class="n">Parameters</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">        <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></div></div>
<p><code>TConstIterator</code> runs front to back, and new bindings are appended to the end of the array. Hence the rule: <strong>in a Blueprint dispatcher, first bound is first called.</strong></p>
<p>That leaves the question of why <code>CustomEvent_1</code> runs first. Not the graph: neither of the two Blueprints contains a node that sets the call order. The lifecycle decides. <code>UGameInstance::Init</code> (<code>Private/GameInstance.cpp:129</code>) runs before the map is loaded, and therefore before <code>BeginPlay</code> on any actor in the world. The world startup timeline is laid out separately in <a href="/en/topics/unreal-engine/gameplay-framework/subsystem-lifecycle-init-order">Subsystem and manager actor lifecycles</a>.</p>
<div class="callout callout--insight">
  <div class="callout__title">Insight</div>
  In the original two-Blueprint setup, lifecycle phases determine the handler order: the binding in <code>Init</code> runs before the binding in <code>BeginPlay</code>. To trace the order in your own project, find every <code>Bind Event to…</code> node targeting that dispatcher and establish when each one executes, including the execution order within a single phase. That information may be spread across several graphs.
</div>

<h2 id="same-name-opposite-order">Same name, opposite order</h2>
<p>The C++ equivalent iterates the other way, with a comment that says why (<code>MulticastDelegateBase.h:292-293</code>):</p>
<div class="highlight" data-lang="cpp">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="c1">// call bound functions in reverse order, so we ignore any instances that may be added by callees
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="k">for</span> <span class="p">(</span><span class="n">int32</span> <span class="n">InvocationListIndex</span> <span class="o">=</span> <span class="n">LocalInvocationList</span><span class="p">.</span><span class="n">Num</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="n">InvocationListIndex</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">;</span> <span class="o">--</span><span class="n">InvocationListIndex</span><span class="p">)</span></span></span></code></pre></div></div>
<div class="table-wrap">
  <table>
    <thead>
      <tr>
        <th></th>
        <th>Call order</th>
        <th>Binding added during the broadcast</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Blueprint dispatcher (<code>FMulticastScriptDelegate</code>)</td>
        <td>registration order — first bound is called first</td>
        <td>skipped; the list is copied before the loop</td>
      </tr>
      <tr>
        <td>C++ delegate (<code>TMulticastDelegate</code>)</td>
        <td>reverse of registration — last bound is called first</td>
        <td>skipped; the loop runs backwards</td>
      </tr>
    </tbody>
  </table>
</div>
<p>So one name, “multicast delegate,” covers two implementations with opposite iteration order. The order a graph relies on is a property of the specific implementation, not of the concept.</p>
<h2 id="same-symptom-different-cause">Same symptom, different cause</h2>
<p>The comment above the copy, <em>“just in case the list is modified by one of the callbacks during the broadcast,”</em> describes a different case with an identical symptom. The copy means that a binding added to a dispatcher <strong>that is currently broadcasting</strong> will not be called in that broadcast. If <code>CustomEvent_2</code> bound <code>CustomEvent_3</code> to <code>OnDelegate_1</code>, the same dispatcher that is calling it right now, <code>CustomEvent_3</code> would stay silent as well. The cause would be the frozen copy taken before the first handler, not the registration order.</p>
<div class="callout callout--note">
  <div class="callout__title">Note</div>
  Both traps belong to the same family: <strong>the state of the binding list at the moment of the call is the only thing that counts</strong>. Anything bound after that does not exist for that call.
</div>

<h2 id="what-the-order-does-not-guarantee">What the order does not guarantee</h2>
<p>Moving a binding earlier in the lifecycle fixes the symptom, and it is a legitimate move. It is worth knowing what it assumes.</p>
<p>Epic does not promise this order. The multicast class documentation says so directly (<code>DelegateSignatureImpl.inl:1024-1025</code>):</p>
<blockquote>
<p>Multicast delegates offer no guarantees for the calling order of bound functions. As bindings get added and removed over time, the calling order may change.</p>
</blockquote>
<p>Removal from the list does not preserve order. <code>RemoveInternal</code> goes through <code>RemoveAtSwap</code> (<code>ScriptDelegates.h:1069</code>), so the last entry jumps into the freed index. The header warns about this on every removal method (<code>ScriptDelegates.h:731</code>, <code>771</code>, <code>1045</code>, <code>1056</code>):</p>
<div class="highlight" data-lang="cpp">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="o">*</span> <span class="n">Removes</span> <span class="n">a</span> <span class="n">function</span> <span class="n">from</span> <span class="k">this</span> <span class="n">multi</span><span class="o">-</span><span class="n">cast</span> <span class="n">delegate</span><span class="err">&#39;</span><span class="n">s</span> <span class="n">invocation</span> <span class="n">list</span> <span class="p">(</span><span class="n">performance</span> <span class="n">is</span> <span class="n">O</span><span class="p">(</span><span class="n">N</span><span class="p">)).</span>  <span class="n">Note</span> <span class="n">that</span> <span class="n">the</span>
</span></span><span class="line"><span class="cl"><span class="o">*</span> <span class="n">order</span> <span class="n">of</span> <span class="n">the</span> <span class="n">delegates</span> <span class="n">may</span> <span class="n">not</span> <span class="n">be</span> <span class="n">preserved</span><span class="o">!</span></span></span></code></pre></div></div>
<p>The practical takeaway: the order is stable as long as nothing unbinds from the dispatcher. Unbinding from this dispatcher anywhere in the project can reorder its remaining listeners.</p>
<div class="callout callout--note">
  <div class="callout__title">Note</div>
  Binding again does not move the event to the end of the list. The <code>Bind Event to…</code> node compiles to <code>EX_AddMulticastDelegate</code> (<code>ScriptCore.cpp:3342</code>), which calls <code>FMulticastInlineDelegateProperty::AddDelegate</code> (<code>PropertyMulticastDelegate.cpp:497</code>), which calls <code>InvocationList.AddUnique</code> (<code>ScriptDelegates.h:1040</code>). <code>AddUnique</code> leaves an existing entry at its current position, so binding a second time does nothing.
</div>

<div class="callout callout--warning">
  <div class="callout__title">Warning</div>
  Relying on the order is fine as long as you can answer two questions: <strong>what sets it</strong> and <strong>what can change it</strong>. If the answer to both is “I do not know,” the graph works by accident.
</div>

<h2 id="what-to-do-about-it">What to do about it</h2>
<p>One pattern forces a decision: <strong>a dispatcher handler that broadcasts another dispatcher while it runs.</strong> It opens a window in which some listeners have not registered yet. Five ways out, each with its own condition. The first three change the graph and have results shown below. The last two are a project convention rather than a change in the nodes.</p>
<h3 id="defer-the-broadcast-by-one-tick">Defer the broadcast by one tick</h3>
<p>Instead of broadcasting <code>OnDelegate_2</code> straight from <code>CustomEvent_1</code>, route it through <code>Set Timer for Next Tick by Event</code> and a separate <code>BroadcastDelegate2</code> event. The <code>OnDelegate_1</code> broadcast then runs through every handler, each one gets to bind, and <code>OnDelegate_2</code> starts with a complete list.</p>
<figure class="bp-embed">
  <div class="bp-embed__canvas" data-bp-src="/blueprints/dispatcher-fix-next-tick.txt" data-bp-height="1340"></div>
  <noscript>
    <p class="bp-embed__fallback">Viewing the graph requires JavaScript.</p>
    <a class="bp-embed__download" href="/blueprints/dispatcher-fix-next-tick.txt" download>Download Blueprint graph (.txt)</a>
  </noscript><figcaption class="bp-embed__caption">CustomEvent_1 does not broadcast OnDelegate_2 directly. It hands that off to BroadcastDelegate2 through Set Timer for Next Tick by Event.</figcaption></figure>
<div class="highlight" data-lang="log">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><pre tabindex="0" class="ue-log"><code><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[1]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[2]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[END TEST]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[3]</span>
</span></code></pre>
</div>
<p><code>[3]</code> landing <strong>after</strong> the <code>[END TEST]</code> marker shows exactly what this solution does: the broadcast moved out of the synchronous execution triggered by the key press and into the next frame.</p>
<p>This applies when no <code>OnDelegate_2</code> listener binds later than the next frame. An actor spawned two frames later, or a widget created on demand, still misses out. It widens the window; it does not remove the dependency.</p>
<div class="callout callout--tip">
  <div class="callout__title">Tip</div>
  <code>Set Timer for Next Tick by Event</code> takes no time input, so it cannot accidentally be set to zero. <code>Set Timer by Event</code> can, and there <a href="/en/topics/unreal-engine/gameplay-framework/set-timer-by-event-time-zero"><code>Time = 0.0</code> clears the timer instead of firing it immediately</a>.
</div>

<h3 id="move-the-binding-to-a-dispatcher-that-is-guaranteed-to-fire-later">Move the binding to a dispatcher that is guaranteed to fire later</h3>
<p><code>CustomEvent_3</code> goes on <code>OnDelegate_3</code>, which is known to fire later. Here the same key press broadcasts it, right after <code>OnDelegate_1</code>.</p>
<figure class="bp-embed">
  <div class="bp-embed__canvas" data-bp-src="/blueprints/dispatcher-fix-later-dispatcher.txt" data-bp-height="1080"></div>
  <noscript>
    <p class="bp-embed__fallback">Viewing the graph requires JavaScript.</p>
    <a class="bp-embed__download" href="/blueprints/dispatcher-fix-later-dispatcher.txt" download>Download Blueprint graph (.txt)</a>
  </noscript><figcaption class="bp-embed__caption">CustomEvent_2 binds CustomEvent_3 to OnDelegate_3 instead of OnDelegate_2.</figcaption></figure>
<div class="highlight" data-lang="log">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><pre tabindex="0" class="ue-log"><code><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[1]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[2]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[3]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[END TEST]</span>
</span></code></pre>
</div>
<p>Cheap and effective, but it still depends on ordering: the order of separate broadcasts rather than the order of handlers within one broadcast. The condition is that nobody moves that call.</p>
<h3 id="turn-the-event-into-state">Turn the event into state</h3>
<p>A dispatcher carries information only at the moment of the call. Whoever arrives late never gets it. A <code>bDelegate2Broadcast</code> bool on the sender side changes that rule: <code>CustomEvent_1</code> sets it before the broadcast, and <code>CustomEvent_2</code>, once its binding is in place, checks it with a <code>Branch</code> and calls <code>CustomEvent_3</code> directly if needed.</p>
<figure class="bp-embed">
  <div class="bp-embed__canvas" data-bp-src="/blueprints/dispatcher-fix-event-to-state.txt" data-bp-height="1080"></div>
  <noscript>
    <p class="bp-embed__fallback">Viewing the graph requires JavaScript.</p>
    <a class="bp-embed__download" href="/blueprints/dispatcher-fix-event-to-state.txt" download>Download Blueprint graph (.txt)</a>
  </noscript><figcaption class="bp-embed__caption">CustomEvent_1 sets bDelegate2Broadcast before the call. After binding, CustomEvent_2 checks the flag with a Branch and makes up for the missed broadcast.</figcaption></figure>
<div class="highlight" data-lang="log">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><pre tabindex="0" class="ue-log"><code><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[1]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[2]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[3]</span>
</span><span class="ue-log__line"><span class="ue-log__cat">LogBlueprintUserMessages</span>: <span class="ue-log__msg">[END TEST]</span>
</span></code></pre>
</div>
<p><code>[3]</code> appears synchronously here, still within the same key press. The late listener does not wait for another broadcast. It reads the state and catches up immediately. This is the only option that survives a listener created after everything else, at the cost of maintaining extra state.</p>
<h3 id="declare-the-order-instead-of-relying-on-it-silently">Declare the order instead of relying on it silently</h3>
<p>If the order is meant to be a contract, write it down: a comment on both <code>Bind Event to…</code> nodes stating which one comes first and what depends on it, an event name that identifies the phase, and an explicit condition that nothing unbinds from this dispatcher. This option documents the existing ordering dependency without changing the graph.</p>
<h3 id="separate-the-phases-bindings-in-one-broadcasts-in-the-next">Separate the phases: bindings in one, broadcasts in the next</h3>
<p>If every <code>Bind Event to…</code> runs in a phase earlier than any call, the order within the list stops meaning anything. Here the dependency disappears instead of moving further out. The condition is that the phase boundary is clearly defined in the project and nobody binds after it.</p>
<h2 id="when-this-matters">When this matters</h2>
<p>As long as every binding to a given dispatcher lives in one Blueprint, the problem barely exists. The order is visible at a glance, and nobody changes it by accident.</p>
<p>The risk shows up once listeners of the same dispatcher spread across different lifecycle phases: GameInstance, a subsystem, GameMode, an actor placed in the level, a spawned actor, a widget created on demand. Call order stops being a property of the graph and becomes a property of the whole project: it is set by the phases in which all the <code>Bind Event to…</code> nodes attached to that dispatcher run. Move one of them to a different phase and the rest shift position in the list.</p>
]]></content:encoded>
      
    </item>
    
    <item>
      <title>Subsystem and manager actor lifecycles — who, when, and in what order</title>
      <link>https://stillcooking.dev/en/topics/unreal-engine/gameplay-framework/subsystem-lifecycle-init-order/</link>
      <pubDate>Tue, 21 Jul 2026 00:00:00 +0000</pubDate>
      
      <guid isPermaLink="true">https://stillcooking.dev/en/topics/unreal-engine/gameplay-framework/subsystem-lifecycle-init-order/</guid>
      <description>Five subsystem base classes, each with a different owner. Where the engine creates and tears down each collection, how world startup relates to actor BeginPlay, and where initialization order is no longer guaranteed.</description>
      <content:encoded><![CDATA[<h2 id="five-collections-five-owners">Five collections, five owners</h2>
<p>A subsystem derives from one of five base classes. Each subsystem type is associated with a different owner and inherits that owner’s lifetime: <code>UEngineSubsystem</code>, <code>UEditorSubsystem</code>, <code>UGameInstanceSubsystem</code>, <code>UWorldSubsystem</code> (plus <code>UTickableWorldSubsystem</code>), or <code>ULocalPlayerSubsystem</code> (<code>Runtime/Engine/Public/Subsystems/Subsystem.h:12-20</code>). Everything below comes from reading the UE 5.8 source.</p>
<p>Choosing the base class is how you declare the subsystem&rsquo;s lifetime. Everything else happens automatically.</p>
<p>All five follow the same contract: <code>ShouldCreateSubsystem(UObject* Outer)</code> → <code>Initialize</code> → <code>Deinitialize</code>. The first call is the exception. It runs on the CDO before an instance even exists, as the header states explicitly: <em>&ldquo;Note: This function is called on the CDO prior to instances being created!&rdquo;</em> (<code>Subsystem.h:49-56</code>).</p>
<p>Under the hood, the collection gathers every non-abstract derived class through <code>GetDerivedClasses(BaseType, …, true)</code> and asks each CDO whether that subsystem should be created (<code>Private/Subsystems/SubsystemCollection.cpp:256,373-391</code>). It stores the resulting instances in a <code>TMap&lt;UClass*, USubsystem*&gt;</code> (<code>Public/Subsystems/SubsystemCollection.h:116-143</code>). One instance per class per Outer isn’t a convention; it follows from the container type. The key is a concrete class, not a hierarchy. If another non-abstract class derives from that base class — a Blueprint child, for instance — its CDO gets asked the same question separately, and the collection ends up holding two independent instances. How this affects which class provides the implementation is covered separately in <a href="/en/topics/unreal-engine/gameplay-framework/should-create-subsystem-picks-the-class">ShouldCreateSubsystem and the subsystem class hierarchy</a>.</p>
<h2 id="where-each-collection-starts">Where each collection starts</h2>
<div class="table-wrap">
  <table>
    <thead>
      <tr>
        <th>Collection</th>
        <th>Created</th>
        <th>Torn down</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Engine (dynamic)</td>
        <td>collection: <code>UEngine::Init</code> — <code>Private/UnrealEngine.cpp:2403</code>; instances: module load — <code>Subsystem.h:72-83</code></td>
        <td><code>UEngine::PreExit</code> — <code>:2757</code>; instances: module unload</td>
      </tr>
      <tr>
        <td>Editor (dynamic)</td>
        <td>instances: module load — <code>Editor/EditorSubsystem/Public/EditorSubsystem.h:9-23</code></td>
        <td>module unload</td>
      </tr>
      <tr>
        <td>GameInstance</td>
        <td><code>UGameInstance::Init</code> — <code>Private/GameInstance.cpp:129</code></td>
        <td><code>UGameInstance::Shutdown</code> — <code>:167</code></td>
      </tr>
      <tr>
        <td>World</td>
        <td><code>UWorld::InitWorld</code> — <code>Private/World.cpp:2414</code></td>
        <td><code>UWorld::CleanupWorldInternal</code> — <code>:6476,6486</code></td>
      </tr>
      <tr>
        <td>LocalPlayer</td>
        <td><code>ULocalPlayer::PlayerAdded</code> — <code>Private/LocalPlayer.cpp:262,270</code></td>
        <td><code>ULocalPlayer::PlayerRemoved</code> — <code>:280</code></td>
      </tr>
    </tbody>
  </table>
</div>
<p>The first two rows are the easiest to get wrong. <code>UEditorSubsystem</code> and <code>UEngineSubsystem</code> derive from <code>UDynamicSubsystem</code>, which automatically populates the collection when a module loads and empties it when that module unloads. Your subsystem won’t exist until its module is explicitly loaded, and the engine won’t report an error if it isn’t.</p>
<div class="callout callout--warning">
  <div class="callout__title">Warning</div>
  The trap in the LocalPlayer row is hidden in the owner’s name. The collection doesn’t start when the <code>ULocalPlayer</code> object is created. It starts in <code>PlayerAdded</code>, after the player has been attached to a <code>UGameViewportClient</code>. Both overloads of that method call <code>SubsystemCollection.Initialize(this)</code> (<code>Private/LocalPlayer.cpp:257-271</code>), while <code>PlayerRemoved</code> deinitializes the collection (<code>:278-280</code>).
</div>

<div class="callout callout--insight">
  <div class="callout__title">Insight</div>
  In PIE, every client instance gets its own <code>UGameInstance</code>. This means the GameInstance, World, and LocalPlayer subsystems are created and destroyed with the PIE session, while Engine and Editor subsystems survive across many sessions in the same editor process. That difference is the most common source of state leaking between PIE runs.
</div>

<h2 id="the-world-startup-timeline">The world startup timeline</h2>
<p>By the time this timeline begins, the Engine and GameInstance collections have already been initialized. <code>UEngine::Init</code> runs during process startup, and <code>UGameInstance::Init</code> runs before the map load that creates the gameplay world.</p>
<div class="callout callout--note">
  <div class="callout__title">Note</div>
  One exception breaks this intuition: <code>UGameInstance::InitializeStandalone</code> creates a dummy world before calling its own <code>Init()</code> (<code>Private/GameInstance.cpp:190-202</code>). The World subsystems for that dummy world are therefore initialized before the GameInstance subsystems. The dummy world is destroyed during the first <code>LoadMap</code>.
</div>

<p>The relevant points in the timeline are all in <code>Runtime/Engine/Private/World.cpp</code>:</p>
<ol>
<li><strong><code>UWorld::InitWorld()</code></strong> calls <code>InitializeSubsystems</code> (<code>:2447</code>) and, near the end, <code>PostInitializeSubsystems</code> (<code>:2610</code>). World subsystems receive both <code>Initialize</code> and <code>PostInitialize</code>.</li>
<li><strong><code>UWorld::InitializeActorsForPlay()</code></strong> runs (<code>:5946</code>). Only then does the engine start handling actors placed in the level.</li>
<li><strong><code>UWorld::BeginPlay()</code></strong> calls <code>OnWorldBeginPlay</code> on every World subsystem and <strong>then</strong> calls <code>AGameModeBase::StartPlay()</code> (<code>:6165-6179</code>).</li>
</ol>
<p>The third point gives us a guarantee that no actor can provide: a World subsystem has been initialized and has already run <code>OnWorldBeginPlay</code> before GameMode starts gameplay. An actor placed in the level receives its <code>BeginPlay</code> during <code>InitializeActorsForPlay</code>/<code>StartPlay</code>, which puts it after the subsystems. That last part is my interpretation of the call order, not a guarantee stated on any single line of engine code, but it follows directly from that order.</p>
<p>An actor spawned during play is a different case. Its <code>BeginPlay</code> fires immediately after it is spawned, so the startup-order question doesn’t apply.</p>
<p>A manager actor comes close to providing the same guarantee, but only when three conditions are met: it derives from <code>AInfo</code> (or explicitly sets <code>bIsSpatiallyLoaded = false</code>), lives in the persistent level, and has no dependency on a streamed sublevel. The <code>AInfo</code> constructor sets <code>bIsSpatiallyLoaded = false</code> and <code>bReplicates = false</code> (<code>Private/Info.cpp:11-45</code>), which is exactly the kind of role Epic designed this class for.</p>
<p>A plain <code>AActor</code> placed in a World Partition level is spatially streamed by default and can be unloaded during gameplay. A subsystem is structurally immune to this class of bug because it doesn’t belong to any <code>ULevel</code>.</p>
<h2 id="where-the-ordering-guarantee-stops">Where the ordering guarantee stops</h2>
<p>The guarantee from the previous section applies only to this ordering. Everything below falls outside it, and that is where the assumption that “the subsystem is always there” breaks down.</p>
<p><strong>There is no declarative ordering between collections.</strong> <code>FSubsystemCollectionBase::InitializeDependency</code> enforces ordering within a single collection and nowhere else. The header states this plainly: <em>&ldquo;Dependencies only work within a collection&rdquo;</em> (<code>Public/Subsystems/SubsystemCollection.h:31-45</code>). A World subsystem that accesses a GameInstance subsystem from inside <code>Initialize</code> has no declarative safeguard. You must either enforce the order yourself or defer that access until <code>OnWorldBeginPlay</code>, when the world has already been assembled.</p>
<p><strong>A dynamic subsystem whose module hasn’t loaded never appears.</strong> A <code>UEditorSubsystem</code> placed in a module with the wrong <code>LoadingPhase</code> simply never reaches the collection (<code>Subsystem.h:72-83</code>, <code>EditorSubsystem.h:9-23</code>). The symptom is misleading: <code>GetEditorSubsystem&lt;T&gt;()</code> returns null even though the class compiles, loads, and looks perfectly fine in the editor.</p>
<p><strong>A class that hasn&rsquo;t been loaded never even makes the list.</strong> This is the same mechanism as the point above, seen from the other side. Non-dynamic collections run their <code>GetDerivedClasses</code> scan once, when the collection is created, and they only see the classes that are in memory at that moment. A Blueprint child of a subsystem with no hard references to that child isn&rsquo;t loaded yet in a packaged build, so its CDO is never asked — and at the default log level a refusal and an absence look identical: both are just a missing line. The editor never shows the problem, because the Content Browser keeps the class in memory. I covered the whole case in <a href="/en/topics/unreal-engine/gameplay-framework/blueprint-subsystem-missing-in-packaged-build">A Blueprint subsystem does not get created in a packaged build</a>.</p>
<p><strong>A conditional <code>ShouldCreateSubsystem</code> eliminates the non-null guarantee.</strong> Epic does this in its own code: <code>UInputDeviceSubsystem</code> returns <code>false</code> on a dedicated server, in a commandlet, and when Slate hasn’t been initialized (<code>Private/GameFramework/InputDeviceSubsystem.cpp:240-252</code>). The consequence is visible in the subsystem’s own accessor. <code>UInputDeviceSubsystem::Get()</code> returns <code>nullptr</code> (<code>:194-197</code>), so every call within the engine is wrapped in an <code>if</code>, three times in <code>ForceFeedbackEffect.cpp</code> alone (<code>:122</code>, <code>:190</code>, <code>:214</code>).</p>
<p>Overriding this hook gives up the very property that often makes a subsystem appealing in the first place. From that point on, every <code>GetSubsystem&lt;T&gt;()</code> requires a null check, and the call site has no way to know whether it is running on a path where the subsystem was created. Sometimes that tradeoff is intentional. The condition in this method doubles as a way of declaring which class in the hierarchy should be the subsystem, and the null check becomes the price of moving the implementation one level down, <a href="/en/topics/unreal-engine/gameplay-framework/should-create-subsystem-picks-the-class">into a Blueprint</a>.</p>
<p><strong><code>DoesSupportWorldType</code> includes editor worlds by default.</strong> A gameplay manager that doesn’t override this method gets an instance in every world opened in the editor, not just in PIE. This happens because <code>UWorldSubsystem</code> overrides <code>ShouldCreateSubsystem</code> through <code>DoesSupportWorldType</code>, whose default implementation allows game, PIE, <strong>and</strong> editor worlds (<code>Public/Subsystems/WorldSubsystem.h:33-66</code>, especially <code>:64-66</code>). If the subsystem also derives from <code>UTickableWorldSubsystem</code>, it ticks from <code>Initialize</code> to <code>Deinitialize</code> for as long as the map remains open in the editor (<code>WorldSubsystem.h:72-106</code>).</p>
<h2 id="confirming-this-in-your-own-project">Confirming this in your own project</h2>
<p>You can verify the entire timeline above in a single editor run. Log four points and include the world type on every line:</p>
<div class="highlight" data-lang="cpp">
  <button type="button" class="code-copy" data-code-copy data-label="Copy" data-copied="Copied!" aria-label="Copy code to clipboard">Copy</button><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="kt">void</span> <span class="n">UMyWorldSubsystem</span><span class="o">::</span><span class="n">Initialize</span><span class="p">(</span><span class="n">FSubsystemCollectionBase</span><span class="o">&amp;</span> <span class="n">Collection</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="n">Super</span><span class="o">::</span><span class="n">Initialize</span><span class="p">(</span><span class="n">Collection</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="n">UE_LOG</span><span class="p">(</span><span class="n">LogMyGame</span><span class="p">,</span> <span class="n">Log</span><span class="p">,</span> <span class="n">TEXT</span><span class="p">(</span><span class="s">&#34;[1] Subsystem::Initialize | World=%s Type=%d&#34;</span><span class="p">),</span>
</span></span><span class="line"><span class="cl">        <span class="o">*</span><span class="n">GetWorld</span><span class="p">()</span><span class="o">-&gt;</span><span class="n">GetName</span><span class="p">(),</span> <span class="p">(</span><span class="n">int32</span><span class="p">)</span><span class="n">GetWorld</span><span class="p">()</span><span class="o">-&gt;</span><span class="n">WorldType</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kt">void</span> <span class="n">UMyWorldSubsystem</span><span class="o">::</span><span class="n">OnWorldBeginPlay</span><span class="p">(</span><span class="n">UWorld</span><span class="o">&amp;</span> <span class="n">InWorld</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="n">Super</span><span class="o">::</span><span class="n">OnWorldBeginPlay</span><span class="p">(</span><span class="n">InWorld</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="n">UE_LOG</span><span class="p">(</span><span class="n">LogMyGame</span><span class="p">,</span> <span class="n">Log</span><span class="p">,</span> <span class="n">TEXT</span><span class="p">(</span><span class="s">&#34;[2] Subsystem::OnWorldBeginPlay&#34;</span><span class="p">));</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// AMyManagerActor::BeginPlay  → [3]
</span></span></span><span class="line"><span class="cl"><span class="c1">// AMyGameMode::StartPlay      → [4]
</span></span></span></code></pre></div></div>
<p>Seeing <code>1 → 2 → 3 → 4</code> in the log confirms the guarantee for one specific project and one specific streaming setup. If <code>[3]</code> appears before <code>[2]</code>, the actor is being spawned rather than placed in the level. Its <code>BeginPlay</code> fires immediately after the spawn and has nothing to do with the world startup timeline.</p>
<div class="section-panel section-panel--checklist">
  <div class="section-panel__label">Checklist</div>
  
<p>Additional checks, each answering a different question:</p>
<ul class="checklist">
  <li><strong>Who created me, and from where?</strong> — set a breakpoint on <code>FSubsystemCollectionBase::AddAndInitializeSubsystem</code>. The call stack shows both the collection and the point in the engine that created it (<code>UEngine::Init</code>, <code>UGameInstance::Init</code>, <code>UWorld::InitWorld</code>, or a module load).</li>
  <li><strong>Am I cluttering up the editor?</strong> — if line <code>[1]</code> appears when you simply open a map without starting PIE, then <code>DoesSupportWorldType</code> hasn’t been overridden. Filtering for <code>WorldType == EWorldType::Game || WorldType == EWorldType::PIE</code> fixes it.</li>
  <li><strong>Does my manager actor really survive?</strong> — check the actor’s <code>bIsSpatiallyLoaded</code> value in the Details panel under World Partition, and confirm that it belongs to the persistent level. Both conditions must be satisfied.</li>
  <li><strong>Was my class asked at all?</strong> — run with <code>-LogCmds="LogSubsystemCollection VeryVerbose"</code>. A <code>CDO choose to not create</code> line means the class was on the list and refused; the absence of that line alongside a missing instance means nobody ever asked it. In that second case the breakpoint from the first check never fires, so on its own it settles nothing.</li>
</ul>

</div>

<p>The ordering guarantee is real, and the engine code enforces it, but it covers exactly one thing: a World subsystem exists before actors in that same world receive <code>BeginPlay</code>. It extends no further than that single axis. Everything above also covers startup only; the order in which a world and a session shut down is a separate question, and this note leaves it open.</p>
<p>The game code has to answer every other question for itself, and the engine won’t even signal that the question came up.</p>
]]></content:encoded>
      
    </item>
    
  </channel>
</rss>
