How to use utility nodes

Utility nodes can be an incredible thing to master. They might look scary and confusing in the beginning but once you are comfortable with them you'll realize that they are pretty easy to use and the power that they offer is amazing.

There are a few ways of using utility nodes. And as always in Maya, there is no right way. You just need to find out which works the best for you.

What we are basically doing with utility nodes is connecting input and outputs to come up with a solution.

We'll go over the following utility nodes:


We'll use a few expressions to demonstrate how to use utility nodes.

Let's start looking at a simple connection. We want a ball to move up on Y when a cube is moved in X.
pBall.translateY = pCube.translateX

For this example all we would have to do is connect the translationY of the ball to the translationX of the cube.

We can do this a few different ways.

Ways to connect nodes together:

  1. via the connection editor:
    Open the connection editor and select the cube and load it on your left. This is your source. On the right (your target) load the ball. Now simple select the translateX on the left and the translateY on the right.
  2. using the hypergraph:
    Open the hypergraph and hover the mouse over the right side of the pBall node. You'll see that the mouse arrow changes to a square with an arrow pointing right. If you hold down the right button, you'll see a list outputs. You have to select the translateY. After you select it, you'll see that there is a line coming out of the right side of the node. Left click on the pCube and select the translateX.
  3. using the hypershade:
    This is very similar to the hypergraph. Open the outliner and the hypershade. Select in the outliner both pCube and pBall and drag them into the work area of the hypershade by using the middle mouse button. Now here, you can connect them the same way as with the hypergraph. You'll have to right click on the right arrow at the bottom right of pBall.
  4. using MEL:
    You could also connect them using the command line. For this connectiong you would have to type: connectAttr pBall.translateY pCube.translateX;

All these things create exactly the same connection. You should find out which was works best for you.

Now that we know how to connect things together, let's move on and transform a simple expression into nodes.
pCube.translateX = pBall.translateY * 2;

All we are trying to do here is to have the ball move twice as fast in Y as that cube in X.

The difference here with our previous example is that we need to multiply the translateY of the ball by 2. We do this by using a multiplyDivide node.

There are a few ways to create a utility node.

Ways to create a utility node:

  1. using the hypershade:
    Open the hypershade and on the left hand side where you have the create Maya nodes tab, go down to General Utilities and click on the Multiply Divide one. The node gets included in your Work Area already
  2. using MEL:
    you can type in the command line: createNode multiplyDivide; If you have the hypershade opened it'll also be included into the Work Area.
  3. using llListUtilities:
    Open the script llListUtilities and expand the filters. If you press on the C on the right of multiplyDivide, you'll create a node which will also be included into the Work Area in the hypershade or into the Input Output connections in the hypergraph.

Note: Using the Input Output connections in the hypergraph is very similar than using the hypershade.

For this example I'll be using the llListUtilities script to create scripts and the hypershade to connect attributes together. But any of the other methods will work just as well.

pCube.translateX = pBall.translateY * 2;

Select both the pBall and pCube on the outliner and middle mouse drag them to the Work Area in the hypershade. Create a multiplyDivide node using the llListUtilities script an open it's attributes (Ctrl-A).

Under the operations tab you have Multiply, Divide and Power. For our example we'll be using Multiply. What this does is multiply the values of Input1 with values of Input2. The input has 3 boxes (X, Y and Z). We'll be just using the first one for our example, the X value.

We need to connect into the Input1 the value of the pball.translateY. We do this by simple right clicking on pBall and selecting the translateY and then clicking on the multiplyDivide node and selecting the Input1/Input1X option. If we look into the Attribute Editor of the multiplyDivide, we see that input1's first box has changed to yellow, which means it has a connection. In the hypergraph we can see an arrow connecting from the pBall to the mutiplyDivide. If you hover over it, you'll see what is being connected to what.

Let's go back to the Attribute Editor. In the input2.X you'll see the value 1. This is what it's being multiplied by. But we wanted our value to be 2 since we are doing pBall.translateY * 2. So by simply changing the value of the input2.X to 2 in the Attribute Editor we do this.

The result of this operation will come out of the right side of the multiplyDivide node and it'll be called Output/OutputX. Since our operation was pCube.translateX = pBall.translateY * 2. All we have to do is connect the output of the multiplyDivide to the input of pCube.translateX and we are done. We do this by right clicking on the right side of the multiplyDivide and selecting the OutputX and then left clicking on the pCube and selecting the translateX input.

Now when we move the ball in Y the cube moves twice as fast in X.

pCube.translateX = (pBall.translateY * 1.5) + (pBall.translateZ / 2);

By looking at the expression I can see determine that I'll need a multiplyDivide doing a multiplication, another multiplyDivide doing a division and a plusMinusAverage to add the two results together.

If instead of a division it was another multiplication, then I could have used the input and output Y of the same multiplyDivide. But since they are different operations, then I have to use different utility nodes.

Select pBall and pCube and move them to your Work Area in the hypershade. Now create 2 multiplyDivides and 1 plusMinusAverage utility nodes. Call them nodeMultiply, nodeDivide and nodePlus. This way it'll be easy to recognize.

Connect the pBall.translateY to the input1X of nodeMultiply. And the pBall.translateZ to the input1X of nodeDivide.

Go into the attributes of nodeMultiply and make sure that the operation is Multiply and change the input2X to 1.5. Now go to the attributes of the nodeDivide and change the operation to Divide and the input2X to 2.

Now we have done the pBall.translateY * 1.5 part and the pBall.translateZ / 2 part. All we need to do is add them together and connect the result to the translateX of pCube.

Connect the outputX of the nodeMultiply to the input1D[n]/[0] of the nodePlus. This puts the first value into the addition. Also connect the outputX of the nodeDivide to the input1D[n]/[1] of the nodePlus. Select the nodePlus and go into the Attribute Editor and make sure that the operation is Sum.

The operation is complete. Now all you have to do is connect the output1D of nodePlus to the translateX of pCube.

If (pBall.translateY > 0)
   pCube.translateX = pBall.translateY * 3;
   pCube.translateX = pBall.translateY * -3;

For this example we'll need only one multiplyDivide node (since we can use both X and Y input and outputs because they are both using the same operation) and once condition node.

Create the two nodes and bring the ball and cue into the Work Area in the hypershade.

Connect the translateY of pBall to both the input1X and input1Y of the multiplyDivide node.

Make sure that the operation is multiply and change both the input2X and input2Y to 3 and -3 respectively.

Let's build the condition.
Connect the pBall.translateY to the firstTerm in the condition Node. Now select the condition node and open it's attributes. Make sure that the operation is Greater Than and that the second term is 0. This is the if (pBall.translateY > 0) part. The first term being the pBall.translateY and the second term the 0.

Now all we have to do is specify what happens when the operation is true and what when it's false.

Connect the outputX of the multiplyDivide to the ColorIfTrue/ColorIfTrueR of the condition node. And the outputY of the multiplyDivide to the ColorIfFalse/ColorIfFalseR of the connection node.

The output of the condition node will depend on translateY of the pBall.

All that it's left to do it connect the output outColor/outColorR of the condition node to the translateX of the pCube.