MPxNode jittering when dragging timeline

Hi, I have an MPxNode with a very simple compute method. All it does is constantly decrease the output’s Y value by 0.1, but if the current frame is at the start then it resets the value to 0. So I’m treating it like a sim. This looks ok if I play the timeline and have the viewport focused. This also looks ok if I bake it to keys. If I drag the timeline back and forth I would expect the object to continue going down, but it’ll start to jitter around. When it’s in this state, the values look perfectly fine and if I click on the viewport the object will pop to where it should be at that point. Does anyone have any ideas why this is happening??

'''
# Execute in Maya
import maya.cmds as cmds

cmds.loadPlugin('tempJiggleNode.py')

obj = cmds.polySphere()[0]

jiggleNode = cmds.createNode('tempJiggleNode')
cmds.connectAttr('{0}.output'.format(jiggleNode), '{0}.t'.format(obj) ) # Connect output to sphere's translate

#cmds.unloadPlugin('tempJiggleNode.py')
'''

import maya.OpenMayaMPx as OpenMayaMPx
import maya.OpenMaya as OpenMaya

commandName = 'tempJiggleNode'

class TempJiggleNode(OpenMayaMPx.MPxNode):
	kPluginNodeId = OpenMaya.MTypeId(0x00000003)
	
	output_value = OpenMaya.MObject()
	currentTime = OpenMaya.MObject()
	
	def __init__(self):
		OpenMayaMPx.MPxNode.__init__(self)
		self.pos = [0,0,0]
	
	def postConstructor(self):
		# Set node's default name
		thisObj = self.thisMObject()
		fnNode = OpenMaya.MFnDependencyNode( thisObj )
		fnNode.setName('jiggleShape#')
		
		# Connect time1.outTime to jiggleNode.currentTime
		currentTimePlug = fnNode.findPlug('currentTime')
		timeDepNode = OpenMaya.MItDependencyNodes( OpenMaya.MFn.kTime )
		if not timeDepNode.isDone():
			timeObj = timeDepNode.thisNode()
			fnNode.setObject(timeObj)
			outTimePlug = fnNode.findPlug('outTime')
			dgMod = OpenMaya.MDGModifier()
			dgMod.connect(outTimePlug, currentTimePlug)
			dgMod.doIt()
		else:
			print 'Cannot find time node in the scene.'
		
	def compute(self, plug, data):
		if plug != TempJiggleNode.output_value:
			return super(TempJiggleNode, self).compute(plug, data)
		
		# First get all attribute from data block
		aCurrentTime = data.inputValue(TempJiggleNode.currentTime)
		# Sim if we above frame 1, otherwise reset
		if aCurrentTime.asTime().value() > 1:
			self.pos[1] -= 0.1
		else:
			# Reset values to 0
			self.pos = [0,0,0]
		
		# Add pos to final output
		outValue = data.outputValue(TempJiggleNode.output_value)
		outValue.set3Double(self.pos[0], self.pos[1], self.pos[2])
		outValue.setClean()
		
		data.setClean(plug)
		return True
	
def creator():
	return OpenMayaMPx.asMPxPtr( TempJiggleNode() )
	
def initialize():
	nAttr = OpenMaya.MFnNumericAttribute()
	TempJiggleNode.output_value = nAttr.create('output', 'output', OpenMaya.MFnNumericData.k3Double)
	nAttr.setWritable(False)
	nAttr.setStorable(False)
	TempJiggleNode.addAttribute(TempJiggleNode.output_value)
	
	uAttr = OpenMaya.MFnUnitAttribute()
	TempJiggleNode.currentTime = uAttr.create('currentTime', 'currentTime', OpenMaya.MFnUnitAttribute.kTime, 0.0)
	uAttr.setKeyable(True)
	TempJiggleNode.addAttribute(TempJiggleNode.currentTime)
	TempJiggleNode.attributeAffects(TempJiggleNode.currentTime, TempJiggleNode.output_value)

def initializePlugin(obj):
	plugin = OpenMayaMPx.MFnPlugin(obj, 'GreenCell', '1.0', 'Any')
	try:
		plugin.registerNode(commandName, TempJiggleNode.kPluginNodeId, creator, initialize)
	except:
		raise RuntimeError, 'Failed to register node: {0}'.format(commandName)
 
def uninitializePlugin(obj):
	plugin = OpenMayaMPx.MFnPlugin(obj)
	try:
		plugin.deregisterNode(TempJiggleNode.kPluginNodeId)
	except:
		raise RuntimeError, 'Failed to register node: {0}'.format(commandName)

I suspect it has to do with the fact that self.pos is not an attribute of the node. In the book “Complete Maya Programming”, the author says:

It is extremely important to use only the MDataBlock to get all the information the node needs to calculate its outputs. No data from outside the MDataBlock should be used in the computation.

From a Python perspective, it makes sense that you would be able to store something in an instance variable. But maybe there’s some underlying mechanism that prevents it.

In any case, you can test it out by making pos an attribute and seeing if the jiggle goes away.

Thanks for the reply. I originally had pos as one of the node’s attributes and the same thing was happening, so I don’t think that’s it.