Skip to content

Node Overview

Akatsuzi edited this page Dec 13, 2023 · 8 revisions

At a high level nodes are structured into two main sections:

  • the class name followed by
  • a definiton for the input types
  • core variables for the RETURN_TYPE, RETURN_NAME, FUNCTION and CATEGORY
  • definitions for the main function and any sub-functions local to the class

Node Class - First Section

This section configures:

  • the class name
  • the inputs and outups
  • the name of the main function
  • the location the node will appear in the node menu

Example:

class CR_ApplyControlNet:

    @classmethod
    def INPUT_TYPES(s):
        return {"required": {"conditioning": ("CONDITIONING", ),
                             "control_net": ("CONTROL_NET", ),
                             "image": ("IMAGE", ),
                             "switch": (["On","Off"],),
                             "strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01})
                             }
               }
               
    RETURN_TYPES = ("CONDITIONING", "STRING", )
    RETURN_NAMES = ("CONDITIONING", "show_help", )
    FUNCTION = "apply_controlnet"
    CATEGORY = "Comfyroll/ControlNet"

Some nodes are more complex than this, but this structure is common to most nodes.


class name

Class names usually use the Upper Camel Case or Pascal Case naming convention.

https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/capitalization-conventions

Example class names:

  • CR_LatentInputSwitch
  • LoadImageFromUrl_
  • UnsamplerHookProvider
  • WAS_Mask_Dilate_Region
  • RgthreeLoraLoaderStack

INPUT_TYPES defintion

The INPUT_TYPES definition must be preceeded by @classmethod.

There are three types of inputs type:

  • required
  • optional
  • hidden

Required inputs must contain a valid value for the workflow to complete successully.

Optional inputs do not require any input. They can be left blank without interrupting the workflow execution.

Hidden data types do not show as inputs on the nodes. Examples include inputs for the Prompt.


RETURN TYPES core variable

Example:

    RETURN_TYPES = ("LATENT",)

RETURN_TYPES must match the return statement in the main function.


RETURN_NAMES core variable

Example:

    RETURN_NAMES = ("latent",)

RETURN_NAMES are required if the labels on the outputs are different to the output data types. If the labels are the same then this variable is not required.


CATEGORY core variable

Example:

    CATEGORY = "Comfyroll/ControlNet"

Function Definitions

The second part of the node class comprises the main function plus any sub-functions local to the class.

This second is WIP.

return statement

Example:

    return (latent_out, )
  • the main function may use multiple returns but only one will execute
  • in most cases this should be a tuple in the format