Quick answer: An On Awake node only fires if the Script Machine is fully initialized before the GameObject activates. Adding the Script Machine at runtime, swapping the graph asset later, or building for IL2CPP without running AOT pre-build all cause the event to be missed. Switch to On Enable for setup that must run on reactivation.
Here is how to fix Unity Visual Scripting graphs whose On Awake node never executes. Your scene plays fine, no errors are logged, but the entry node sits unhighlighted while the rest of the graph waits for input that never comes. Visual Scripting’s lifecycle nodes have specific timing requirements, and in builds the situation is complicated by an AOT pre-build step that is easy to forget.
The Symptom
You build a Script Machine graph that begins with On Awake, wired to setup logic. In Play mode, the setup never runs. The graph editor shows no orange highlight on the Awake node when entering Play mode. Other event nodes (like On Update) work fine.
In a build, an even broader symptom: the entire graph does nothing on iOS or Switch, but works in editor.
What Causes This
Script Machine added at runtime. If your code adds ScriptMachine via AddComponent, Awake has already fired on the GameObject. The new component initializes too late to receive the event.
Graph asset assigned after activation. The Script Machine has Source set to Graph and a public field for the asset. If your asset is loaded asynchronously and assigned after Awake, the graph misses its own Awake.
OnEnable vs Awake confusion. Pooled objects are typically deactivated and reactivated, but Awake only fires the first time. Pulling an object from a pool will not re-fire Awake.
AOT pre-build missing for IL2CPP. Visual Scripting uses runtime reflection for user types. IL2CPP strips reflection metadata. The fix is the AOT pre-build step that generates link.xml entries and stub assemblies.
The Fix
Step 1: Use OnEnable for setup that must always run.
In your graph, replace On Awake with On Enable. OnEnable fires when the GameObject activates and again on every reactivation. For pooled objects this is the right hook.
Step 2: Confirm the graph asset is assigned in the inspector at edit time. Avoid loading graphs at runtime if you need Awake to fire reliably. If you must load dynamically, use OnEnable inside the graph and toggle the GameObject inactive/active after assignment:
using UnityEngine;
using Unity.VisualScripting;
public class RuntimeGraphLoader : MonoBehaviour
{
[SerializeField] private ScriptGraphAsset graph;
void Start()
{
gameObject.SetActive(false);
var sm = gameObject.AddComponent<ScriptMachine>();
sm.nest.source = GraphSource.Macro;
sm.nest.macro = graph;
gameObject.SetActive(true); // Now OnEnable fires on the graph
}
}
Step 3: Run AOT pre-build before building for IL2CPP. Open Edit → Project Settings → Visual Scripting, scroll to the AOT Pre-build section, and click Build Pre-built Assemblies. Re-run this any time you add new node types or third-party Visual Scripting integrations.
Step 4: Add types to the type options. If your graph references custom MonoBehaviour types, those must be in Project Settings → Visual Scripting → Type Options. After adding, click Regenerate Units.
Step 5: Verify execution with a debug log. Drop a Log node directly off the entry event. If the log appears, the entry fired. If not, the entry node is the problem.
State Machine vs Script Machine
State Machines have their own lifecycle: On Enter State fires when a state becomes active. If you put logic in a State graph and expect Awake-style behavior, use On Enter State on the initial state instead. Awake nodes inside a State graph only fire if that state is active when the State Machine itself awakes.
Pooling Pitfall
Object pooling is the most common reason Awake nodes seem unreliable. The first activation fires Awake correctly. Every subsequent reuse from the pool does not. Always use OnEnable for per-spawn initialization.
“Awake fires once. OnEnable fires forever. For setup that must repeat, OnEnable is the right hook.”
Related Issues
For runtime IL2CPP failures, see IL2CPP Managed Stripping. For pooling state issues, see Object Pooling Returning Wrong State.
OnEnable for repeating setup. AOT pre-build before every IL2CPP build. The graph runs.