Pyobjects/Global Var Set If Not Exists
Initialize a value once, keep it across runs
- value
- *
A plain "set" node overwrites a value every time it runs. That's usually what you want - except when it isn't, like a counter you want to keep incrementing across separate queue runs, or a seed you want fixed the first time and left alone after that. This node covers that second case: it writes value under key in LogicUtils' shared in-memory store, but only if that key doesn't already hold something. Run it once, it sets the value. Run it fifty more times, and every one of those is a no-op that just hands back whatever's already there.
That "initialize once" behavior is the whole reason this exists next to the plain set node. Global state in ComfyUI usually resets with every queue unless you deliberately work around it, and this is the workaround: the first run seeds the value, every subsequent run in that same ComfyUI session reads it back unchanged, until you restart the server (which clears the whole in-memory store) or use GlobalVarRemoveNode to explicitly clear that one key.
How it works
key and value go in; the node checks whether key is already present in the shared dictionary. If not, it stores value there. Either way, it returns whatever ends up stored under that key on the wildcard * output - so you can chain it straight into whatever uses the value, and not just into a separate get node elsewhere. It's marked as an output node, so it's allowed to run even with nothing wired downstream.
Inputs and outputs
- key (default
my_key) - the name this value lives under. Reuse the same key in two places and they'll fight over the same slot. - value (default
my_value) - the flexible*input: whatever you want to persist for the session, the first time this runs.
Output is the stored value, on *.
Installing ComfyUI-LogicUtils
ComfyUI Manager: Install Custom Nodes → search "ComfyUI-LogicUtils" → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/aria1th/ComfyUI-LogicUtils
Restart ComfyUI. No dependencies.
Worth knowing
This sits alongside GlobalVarGetNode (read it back), GlobalVarRemoveNode (clear it early), and GlobalVarSaveNode/GlobalVarLoadNode (the disk-persisted, survives-a-restart version of the same idea) as one small state subsystem inside aria1th's (AngelBottomless's) LogicUtils pack. Remember that "in memory" means "gone on restart" - if you need the initialized value to survive ComfyUI actually restarting, this node alone won't do it; you'd want the Save/Load pair writing to a file instead. The pack's README doesn't document any of this explicitly (it openly says documentation is still pending), and public commits stopped in January 2026, so this write-up is largely inferred from the node's own inputs - reasonable to trust, but worth testing your specific use case once before building a whole workflow around it.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| key | STRING | my_key | — |
| value | * | my_value | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| * | * | — |