ComfyUI Node Runs on cloud

Layer Remove

Thin a stack down before it flattens

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
Layer Remove
  • layers
  • layers
  • count
  • dropped
first_index0
last_index-1
name
match
visibility

Every compositor workflow accumulates junk: the guide layers you drew to place things, the hidden experiment you toggled off and forgot, the layer that served its purpose three edits ago. Layer Remove is the trash can. It drops the layers that match - a run of the stack by index, a name, whether the compositor draws them, or all three at once - and hands back a clean stack numbered from 0 at the back.

The three filters

The node filters on three independent axes and removes what all of them select, so you can be as broad or as narrow as you like:

  • Index range - first_index to last_index, counting 0 from the bottom. Left at 0 and -1, the range spans every layer.
  • Name - text a layer's name must carry. match picks between contains ('guide' removes Guide and Guide Grid) and exact (removes only a layer called exactly that). Case is ignored. Blank reaches every name in the range.
  • Visibility - any, visible only, or hidden only. "Clear every hidden layer out of the document before render" is a one-node operation, and it's the use I reach for most.

The canonical workflow move: keep a guide layer in the stack while you position things, then drop a Layer Remove with visibility = hidden only just upstream of Create Layered Image - anything you've switched off quietly vanishes from the final flatten.

Outputs

Besides the trimmed layers, the node answers two counts that make it graph-programmable. count is how many layers remain, and dropped is how many went - both useful to a switch that handles an empty result, or just to surface in the console when a filter took more than you expected. It's the "so a filter that took too much shows" feature, and it will absolutely save you the first time a name filter matches more than you meant.

Watch the numbering when you chain edits: removal renumbers the survivors from 0, so a layer you address by index later may have moved. If you're removing and then editing, address by layer_name and the shuffle stops mattering. (This is a pack-wide convention, not just this node - the moment you reorder or remove, index-based wiring needs re-reading.)

Installing it

Layer Remove comes with WAS Node Suite. ComfyUI Manager → search "WAS Node Suite v3", or:

cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui.git

Restart ComfyUI. Needs ComfyUI 0.14.0+ and Python 3.10+. v3 installs no pip packages of its own, so there's nothing else to fetch.

Where people trip

The symmetry trap: Layer Remove and Layer Select look like mirror images but they're not quite - Remove keeps what doesn't match, Select keeps what matches. If your stack suddenly empties, you've built your filter as a Select. And "dropped more than intended" usually comes from a contains match being broader than you thought; prefer exact when you name your layers, and always glance at the dropped count before you flatten. Removing layers is destructive by design, but the node never touches the actual image data on disk - it's all still there upstream if you undo the wire.

CategoryWAS Suite/Image/Layers

Inputs (6)

NameTypeDefaultDescription
layersLAYERSThe stack to thin out. Wire in Add Layer, Layer Edit or anything else answering a LAYERS document.
first_indexINT0-16384–16384Lowest layer removed, counting 0 from the back of the stack. -1 is the front layer, -2 the one under it.
last_indexINT-1-16384–16384Highest layer removed, counted the same way. -1 = the front of the stack, so 0 and -1 together reach every layer.
nameSTRINGText a layer's name has to carry to be removed. Blank reaches every name in the range. Case is ignored, so 'guide' matches Guide.
matchCOMBOHow name is compared. 'contains' removes Guide Grid for 'guide'; 'exact' removes only a layer called exactly that.
visibilityCOMBOWhich layers the filter reaches by their switch. 'any' ignores it, 'visible only' removes what the compositor draws, 'hidden only' clears out what it skips.

Outputs (3)

NameTypeDescription
layersLAYERSWhat is left, numbered from 0 at the back, for Create Layered Image or another edit.
countINTHow many layers are left, for a switch that handles one.
droppedINTHow many were removed, so a filter that took too much shows.