π Latent OR Gate (Auto)
Which latent is actually there? This node decides for you
- latent_a
- latent_b
- latent
ComfyUI is full of switches that need a human behind them. rgthree's Any Switch, the core "Switch (any type)" node, all of them want you to flip something or feed them a boolean. But what if the graph could tell which of two inputs was the real one on its own? That's the whole pitch of π Latent OR Gate (Auto) - class LatentORGate, living in Latents > Utils. Wire two latents in, it keeps whichever actually holds information, and passes one latent out the other side. No toggling, no extra branch to maintain.
The author doesn't oversell it. The README is honest that this started as "I explained the problem to Grok and it gave me this," then got shared. It's a single __init__.py file with no model downloads and no dependencies beyond torch, which ComfyUI already requires. There's nothing to configure on install and nothing to break.
The "OR" is content-based, not boolean
The mechanism is simpler than the name suggests. For each input the node computes the mean absolute value of the latent samples - torch.mean(torch.abs(samples)) - and compares it against a threshold. Anything above the threshold counts as "has information"; below it counts as empty. Then it applies a small truth table:
- A has info, B doesn't β pass
latent_a - B has info, A doesn't β pass
latent_b - Both have info β tiebreak via
priority - Neither has info β safe fallback,
latent_a
Why does a magnitude check work at all? Because ComfyUI's "empty" latents genuinely are empty. EmptyLatentImage produces a tensor of zeros, so its mean absolute value is 0 - comfortably under the default threshold of 0.00001. A latent that came out of a real VAE encode has nonzero values everywhere, so it reads as live. Empty vs. real is exactly the distinction you usually care about.
The inputs that matter
latent_a/latent_b(LATENT, both required). Both areforceInput- you must wire them from real nodes; you can't type in a fixed value. This is an auto-switcher, not a preset.threshold(FLOAT, default0.00001). The author's own description: "Anything above this = 'has information'". Leave it alone unless the gate is misfiring.priority(AorB, defaultA). Only used when both inputs read as live - which is more common than you'd think, since any real latent clears the bar.
The single output, latent, is a LATENT - wire it into whatever consumes the chosen stream, typically a KSampler or a video model's latent input.
Install
The README's own instructions work: make a folder in custom_nodes, drop the __init__.py in it, restart. But since it's a real repo, the normal ways work too:
cd ComfyUI/custom_nodes
git clone https://github.com/allegiancerecords0-afk/Comfyui-LatentOR
then restart ComfyUI. Or, easier: ComfyUI Manager β Install Custom Nodes β search "Comfyui-LatentOR". It'll show up under Latents > Utils as "π Latent OR Gate (Auto)". Apache-2.0 licensed, so no qualms about using it.
Where people get burned
The "has information" test is magnitude-based, not occupancy-based, and that's the one thing to keep in your head. A valid but quiet latent - say, a heavily masked inpaint branch where most of the tensor is zeros - can have a low mean and get read as "empty," silently sending you down the other path. If the gate ever picks what looks like the wrong branch, threshold is the first knob to turn.
The flip side: anything nonzero counts as live. And a bypassed or muted node isn't detected - bypass passes its input through unchanged, so this node reads content, not execution state. If your goal is "does this branch actually run," this isn't that. But if your goal is "give me whichever latent isn't a zeroed placeholder," it does exactly that, with one less toggle to forget.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| latent_a | LATENT | β | |
| latent_b | LATENT | β | |
| thresholdopt | FLOAT | 0.00000β10 | β |
| priorityopt | COMBO | A | 2 options: A, B |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| latent | LATENT | β |