ComfyUI Node: Swap

Class Name

Swap

Category
antrobots-ComfyUI-nodepack/flow-control
Author
antrobot (Account age: 3193days)
Extension
antrobots ComfyUI Nodepack
Latest Updated
2025-04-02
Github Stars
0.02K

How to Install antrobots ComfyUI Nodepack

Install this extension via the ComfyUI Manager by searching for antrobots ComfyUI Nodepack
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter antrobots ComfyUI Nodepack in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

Swap Description

Interchange input values based on condition, toggle for swapping or keeping original order, offers flexibility in workflow.

Swap:

The Swap node is designed to interchange the values of two inputs based on a specified condition. This node is particularly useful in scenarios where you need to dynamically switch between two data streams or values during the execution of a workflow. By providing a simple boolean toggle, the Swap node allows you to control whether the values should be swapped or remain in their original order. This functionality can be beneficial in various creative processes, such as altering the flow of data or modifying the sequence of operations, thereby offering flexibility and control over the execution path.

Swap Input Parameters:

val1

This parameter represents the first value to be considered for swapping. It can be of any data type, allowing for a wide range of inputs to be used. The impact of this parameter is directly related to the doSwap condition; if swapping is enabled, this value will be exchanged with val2.

val2

Similar to val1, this parameter is the second value involved in the potential swap. It also accepts any data type, providing versatility in its application. The role of val2 is to be swapped with val1 when the doSwap condition is true.

do Swap

This is a boolean parameter that determines whether the swap operation should occur. When set to true, the values of val1 and val2 are interchanged. If false, the values remain in their original order. This parameter is crucial for controlling the behavior of the node and allows for dynamic decision-making within a workflow.

Swap Output Parameters:

valA

This output represents the first value after the swap operation. If doSwap is true, valA will contain the original value of val2. If doSwap is false, valA will simply be the original val1.

valB

This output corresponds to the second value post-swap. When doSwap is true, valB will hold the original value of val1. Conversely, if doSwap is false, valB will be the original val2. These outputs allow you to access the results of the swap operation and use them in subsequent nodes or processes.

Swap Usage Tips:

  • Use the doSwap parameter to dynamically control the flow of data in your workflow, enabling or disabling the swap based on specific conditions or triggers.
  • Consider using the Swap node in conjunction with other nodes that require conditional data manipulation, as it can provide a simple yet effective way to alter data paths without complex logic.

Swap Common Errors and Solutions:

TypeError: unsupported operand type(s)

  • Explanation: This error may occur if the inputs val1 or val2 are not compatible with the expected data types.
  • Solution: Ensure that both val1 and val2 are of compatible types or convert them to a common type before using the Swap node.

ValueError: invalid boolean value

  • Explanation: This error can happen if the doSwap parameter is not set to a valid boolean value.
  • Solution: Verify that doSwap is explicitly set to either true or false to ensure proper operation of the node.

Swap Related Nodes

Go back to the extension to check out more related nodes.
antrobots ComfyUI Nodepack
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Playground, enabling artists to harness the latest AI tools to create incredible art.