View Full Version : DG Node update logic

11 November 2012, 08:33 AM
I'm confused how DAG nodes actually updates. So here's simple code, almost directly from Maya pluginWizard.

#include "DGUpdateNode.h"

#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>

#include <maya/MGlobal.h>

MTypeId DGUpdate::id( 0x00011 );

MObject DGUpdate::input;
MObject DGUpdate::output;

DGUpdate::DGUpdate() {}
DGUpdate::~DGUpdate() {}

MStatus DGUpdate::compute( const MPlug& plug, MDataBlock& data )
MStatus returnStatus;

if( plug == output )
MDataHandle inputData = data.inputValue( input, &returnStatus );

if( returnStatus != MS::kSuccess )
MGlobal::displayError( "Node DGUpdate cannot get value\n" );
MGlobal::displayInfo( "Updated\n" );
float result = inputData.asFloat();
MDataHandle outputHandle = data.outputValue( DGUpdate::output );
outputHandle.set( result );
} else {
return MS::kUnknownParameter;

return MS::kSuccess;

void* DGUpdate::creator()
return new DGUpdate();

MStatus DGUpdate::initialize()
MFnNumericAttribute nAttr;
MStatus stat;

input = nAttr.create( "input", "in", MFnNumericData::kFloat, 0.0 );

output = nAttr.create( "output", "out", MFnNumericData::kFloat, 0.0 );

stat = addAttribute( input );
if (!stat) { stat.perror("addAttribute"); return stat;}
stat = addAttribute( output );
if (!stat) { stat.perror("addAttribute"); return stat;}

stat = attributeAffects( input, output );
if (!stat) { stat.perror("attributeAffects"); return stat;}

return MS::kSuccess;


Now when I change input value. I should get "Updated" print right? However I'm not getting any prints so what I'm doing wrong?

As far as I understand update process it goes like this.
When ever input plug changes output plugs which are specified to be affected by input plug are marked dirty and all plugs where output plugs are connected. When Maya next time updates all dirty plugs get re-evaluated from child first order.

Can someone clear this up for me, please?

11 November 2012, 03:56 PM
First off, DAG and DG are two distinct types of nodes. All nodes in Maya are DG (dependency graph) nodes. DAG (directed acyclic graph) nodes are a subset of DG nodes that represent scene hierarchy.

You almost have the process correct:

1. When an input on a node is updated, the first process is the DG dirty stage. In the DG dirty stage, it will look at attributeAffects relationships on your node and dirty dependents. Similarly it does the same for connections downstream.

2. Next, is the DG evaluation stage. Maya uses a lazy evaluation. It is a pull based scheme. So it will only attempt to update a dirty value if it is requested. That's the key. So it won't just update because you've changed the input. It will only update if you change the input (to dirty the output) and then request the output (a getAttr works just fine).

11 November 2012, 07:26 AM
Thanks for your help. It makes more sense now.

CGTalk Moderation
11 November 2012, 07:26 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.