ComfyUI Node

union

Merge sets and get the duplicates collapsed for free

By StableLlama·Created about a year ago·Updated 4 days ago· 48
union
  • set1
  • set2
  • set3
  • set4
  • SET

union merges two or more sets into one and returns every element that appeared in any of them - with duplicates collapsed, because that's what a set does. It's the "combine these pools" node, and the dedupe is the feature, not a side effect.

This is probably the first SET node you'll reach for, because combining collections is a constant need in workflow building. Merge two tag lists into one master set. Combine a style-keyword set with a prompt-tag set and know the result has no repeats. Merge frame pools from two generation batches into one set to feed through contains or length. The output is itself a SET, so it chains naturally - union the result with another set, or hand it to convert to LIST when you need it ordered and indexable.

How it works

The mechanism is Python's set.update() applied in sequence: the node copies set1, adds everything from set2, then set3, then set4 if you provided them. Any element present in at least one input ends up in the result exactly once.

Two things to internalize:

  • Non-destructive. set1 is copied, so all your input sets survive untouched for use elsewhere.
  • "Up to four sets" is a real limit. The schema takes set1 and set2 as required, plus set3 and set4 as optional. Want to merge five? Chain the node.

Inputs and output

  • set1, set2 (SET) - the two required sets.
  • set3, set4 (SET) - optional extra sets to merge in.
  • SET (output) - every element from any input, deduplicated.

The four-slot design is the nice part - most of this pack's set operations only take a pair, but union lets you combine a whole set of sources in one node.

Installing

It's part of Basic data handling by StableLlama. ComfyUI Manager is easiest - search "Basic data handling", install, restart ComfyUI. Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Restart after cloning. No dependencies, no model downloads - the pack is pure Python, so this installs instantly and cleanly.

Common issues

The predictable surprise is people expecting union to preserve duplicates. It can't and won't - that's the entire contract of a set. If you need to keep repeats, you want a LIST merge instead (the pack's append/extend LIST nodes), not a union. And remember sets only hold hashable values: unions of sets containing lists or tensors will error on unhashable types. Keep the SET category fed from type-specific creators and you're fine.

CategoryBasic/SET

Inputs (4)

NameTypeDefaultDescription
set1SET
set2SET
set3optSET
set4optSET

Outputs (1)

NameTypeDescription
SETSET