If Else For Empty Object
A ternary switch for ComfyUI, built with empty lists in mind
- on_true
- on_false
- any
ComfyUI's graph is a DAG - data flows one direction, and there's no built-in if/else the way you'd write it in code. IfElseForEmptyObject is one of the small handful of nodes that fake it: give it a boolean and two values, and it hands back whichever one the boolean points to. Simple ternary, a if condition else b, as a node.
What makes it worth a specific mention rather than being just another switch node is the name and the pack author's own framing: it's built to handle the case where the values you're branching on are lists, not just single values. That's a genuinely fiddly corner of ComfyUI - a lot of switch-style nodes assume scalar inputs and misbehave or silently unwrap when you hand them a list instead. This one is meant to hold up under that case.
It ships in comfyui-easyapi-nodes, lldacing's utility pack for people driving ComfyUI headlessly through its API, where conditional branches based on whether some upstream data came back empty are a much more common need than they are in a hand-built UI workflow - an API caller might send an empty prompt list, an empty image, or nothing at all, and your graph needs to do something sane about it instead of erroring out.
How it works
No magic - it evaluates the boolean input you give it and routes on_true or on_false through to the single output accordingly. It doesn't compute the boolean itself; you're expected to feed it one, typically from an upstream check. The pack's own IsNoneOrEmpty node - which tests whether a value is None, an empty string, an empty list, or an empty dict - is the natural thing to wire into boolean here: check for emptiness first, then let IfElseForEmptyObject pick the branch.
The inputs and outputs that matter
boolean(BOOLEAN, required) - the condition. Usually the output of an emptiness check upstream, but any boolean works.on_true(any type, required) - what gets returned when the boolean is true.on_false(any type, required) - what gets returned when the boolean is false.- Output:
any- whichever branch was selected, passed through as-is so you can wire it into whatever the rest of your graph expects.
Both branches accept ComfyUI's wildcard * type, so you can switch between images, strings, lists, whatever you've got - as long as whatever's downstream can actually handle either possibility.
How to install it
Via ComfyUI Manager, searching comfyui-easyapi-nodes. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/lldacing/comfyui-easyapi-nodes.git
cd comfyui-easyapi-nodes
pip install -r requirements.txt
Then restart. No models or heavy dependencies involved.
Common issues & troubleshooting
Both branches get evaluated anyway. This is a ComfyUI-wide gotcha, not specific to this node: unless the rest of your graph is set up for lazy evaluation, both on_true and on_false inputs may still get computed upstream before this node picks between them, since ComfyUI generally executes everything feeding into a run rather than short-circuiting branches. If skipping expensive work on the untaken branch matters, you need the upstream nodes structured for lazy eval - this pack's "without output" save nodes exist partly for that reason, as cheap pre-nodes that only do real work when actually reached.
Downstream node rejects the output type. Because the output is typed *, ComfyUI won't catch a type mismatch for you at graph-build time. If on_true and on_false are genuinely different types, make sure whatever consumes the output can handle both, or you'll only find out at runtime.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| boolean | BOOLEAN | — | |
| on_true | * | — | |
| on_false | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| any | * | — |