Using Variables in a Multishot Context

Graph Scope Variables are an important tool, enabling a native multishot compositing workflow in Nuke.

They allow you to define, store, and access the data required for multiple contexts or scopes in a single Nuke script.

Once Variables are created, you can more easily manage scopes by using VariableGroup nodes in your node graph.

You can also switch the scope based on the Variables available with the VariableSwitch node.

These Variables provide the flexibility to work at scale and speed up laborious workflows, all whilst ensuring consistency and continuity across the project.

Note:  You can think of Variables as containers that hold information, which can then be referenced and called upon in various different locations.

Note:  Differences between Graph Scope Variables and the Graph State Variables in Katana: Although both provide similar functionality, VariableGroup nodes in Nuke automatically inherit GSVs from their parent(s) and allow these to be overridden to define a different or modified 'Scope' for the group.

Accessing Variables

There are two Variables tabs where you can view and manage Variables. One at the root level within the Project Settings panel, and another one inside every VariableGroup node or LiveGroup node.

1.   Open Edit > Project Settings, and navigate to the Variables tab:

This displays all the VariableGroups, Variable Sets, Variables and Variable Values within a project (.nk script).

OR

2.   Create a VariableGroup node or LiveGroup node, and navigate to the Variables tab:

Note:  The Variables tab in the VariableGroup or LiveGroup node shouldn’t be considered the whole knob value but a convenience to allow Variables to be edited more easily, and making it possible to change an inner group GsvKnob value from its parent VariableGroup node. To view all VariableGroup nodes, navigate to the Project Settings Variables tab.

Note:  The Variables (GsvKnob) can also be obtained via Python. See Editing Variables with Python.

Tip:  A Variables tab also shows on the LiveGroup node. This allows you to work with Variables on shared scripts.

Adding and removing Variables

You can manage your Variables either in the VariableGroup node’s Variables tab, or the Project Settings > Variables tab.

The Variables tab allows you to create, edit and remove Variables and Variable Sets.

To add a Variable on its own, select the button. This will add a single Variable to whichever group or set you currently have selected.

To add a Variable Set, select the folder button. This acts as a group of Variables, and you can add further Variables within it.

To remove a Variable or Variable Set, select the button.

Name your Variable something unique and give it a Value.
The Name is what will be used elsewhere in your Nuke script to reference this Variable.
The Value is the data that the Variable holds, to be substituted in.

To edit a Name or Value simply double click in the relevant field.

There are two types of Value:

- String is a single text value. This is the default option.
- List allows you to create multiple string options for what are the possible acceptable values for the Variable.
Any updates to the Variable Names will update the Variables tab in both the VariableGroup node and the Project Settings panel.

Note:  Valid Names are the ones that begin with an alpha character [a-zA-Z] or '_' (underscore), followed by any number of alphanumeric characters or underscores. Examples of valid names are: '_shot', 'Shot', 'shot01'. Non compliant names will be ignored by the GsvKnob.

List - Usage

The List option can be used to add a list of shots, for example:

Tip:  The List option is particularly useful for organising your script, as you can set this up to change the visibility of each Variable by its Value. See Configuring Visibility with the Variables Panel.

Tip:  The List option is also useful when using the VariableSwitch node, allowing you to switch inputs based on the current scope being viewed or rendered. Because you have a fixed set of possible Values, you can use the values to choose between specific shots. See VariableSwitch Node in a Multishot Context.

Referencing Variables

Once created, you can reference your Variables in nodes and expressions by referencing %{Variable}, for example: %Variable_01

Additionally, Variables within Variable Sets can be referenced if you prepend the Variable Set name %{VariableSet.Variable}, for example: %VariableSet_A.Variable_A

Recursive evaluation of Variables is also supported, giving the option of creating Variables which depend on one another. Special delimiters ‘{‘ and ‘}’ can be used to indicate where a valid Graph Scope Variable expression starts and finishes.

When referencing Variables in expressions, the order of evaluation of expressions in Nuke after the introduction of Graph Scope Variables is:

Graph Scope Variables

TCL

OpenAssetIO entity references

Nuke’s view and frame ranges

Variables example 1: File path

Variable Name

Variable Value (String)

shot

s0001

With a file path set to /Volumes/%shot/file-####.exr, and a shot Variable defined with value s0001, the referred path would be evaluated to: /Volumes/s0001/file-####.exr.

Variables example 2: Recursive Path Evaluation

Recursive evaluation allows you to create Variables which depend on one another, by using special delimiters ‘{‘ and ‘}’ to indicate where a valid Graph Scope Variable expression starts and finishes. This means you can include multiple Variables in one path:

Note:  No validation is used against Variable values.

Variables example 3: Disable knob

Variable Name

Variable Value (List)

shot

shot1

shot2

shot3

You could use a List Variable in an expression on the disable knob [string equal shot3 %shot] — this would disable the node when the shot Variable is equal to shot3.

Note:  You can also use the command line to specify Variables for command line render. See Specifying Variables for Command Line Render.

Overriding Variables

New Variables can override a Variable in a parent group, this is represented in the UI with a yellow icon next to the Variable. Removing the override Variable will revert it back to inheriting from the parent.

Tip:  Setting up Variable groups is made easier with the use of VariableGroup nodes, explained here — Using the VariableGroup Node.

Tip:  See our Multishot Tutorial to learn more about how Graph Scope Variables, VariableGroup, and VariableSwitch nodes work together in practice.