ComfyUI Node

Function End

The return statement of this pack

By Duanyll·Created 11 months ago·Updated 4 months ago· 2
Function End
  • return_value
  • CLOSURE
capturetrue

Function End is where a ComfyUI Functional function returns. You build a function by dropping Function Parameter nodes for each argument, wiring them into any subgraph, and terminating that subgraph in a Function End node. Whatever you connect to its return_value input is what the whole thing hands back when called. If Function Parameter is the def, this is the return.

The inputs

  • return_value - any type. The function's output. Connect your subgraph's last node here.
  • capture - a BOOLEAN, default True. This controls the pack's capture behavior.
  • output - a CLOSURE, ready to feed into Call Function, the high-order nodes, or even back into a function as an argument.

The capture flag is the one genuinely confusing input, so let's be precise. When capture is enabled (the default), nodes in the function body that don't depend on any Function Parameter are evaluated once at function-definition time and captured - reused on every call. That's the mechanism that makes it safe to load a checkpoint or a text encoder inside a function body without re-loading it per call. The tradeoff: those captured values get baked into the closure.

Disable capture (set it to False) when you plan to call the function remotely. Call Remote Function serializes the closure and ships it to another ComfyUI instance; captured values - models, samplers - can't be serialized. With capture off, everything runs fresh inside the remote body, which is what you want there.

How it works

Function End never actually runs. It's a marker: when you queue the workflow, the pack's transform hook walks backward from this node to find the whole function subgraph, splits it into parameter-dependent and captured parts, and rewrites the Function End into an internal Create Closure node carrying the body as JSON. If you ever see an error saying "The Function End node is a marker and should never be executed directly," that's the hook failing to do its job - usually a ComfyUI update breaking the pack's internals, which the README explicitly warns about.

The one-output rule

Each function returns exactly one value. That's a hard limit. If your function needs to return several things, bundle them into a LIST (via Basic Data Handling) and unpack downstream. It's a small constraint, but it shapes how you design function bodies - plan your returns.

Where people get burned

  • Loose ends. "Prompt has no outputs" usually means a Function Parameter output is reaching an output node without passing through Function End (or Inspect). Every parameter must terminate in the End.
  • Forgetting to call it. Defining a function and never wiring the CLOSURE into a Call Function means it never runs.
  • Captured models + remote calls. Leave capture on and call remotely and you'll hit serialization errors; set it False.

Installing it

Part of Duanyll/comfyui_functional. ComfyUI Manager: search "Duanyll/comfyui_functional", or:

cd ComfyUI/custom_nodes
git clone https://github.com/Duanyll/comfyui_functional
# restart ComfyUI

No models, no pip deps. Learn this node together with Function Parameter and Call Function - the three are a unit, and understanding capture is the difference between a function that works and one that confuses you.

Categoryduanyll/functional

Inputs (2)

NameTypeDefaultDescription
return_value*
captureBOOLEANtrue

Outputs (1)

NameTypeDescription
CLOSURECLOSURE