问题
When I dirty an input plug for example mFileAttr
, the setDependentsDirty()
gets properly invoked, but the value of fileName
plug is still the old value! I only see it getting updated once it goes through compute()
. How can I access the new value in setDependentsDirty()
function since it's indeed triggered by the plug value update?
MStatus FNode::setDependentsDirty(const MPlug& plug, MPlugArray& plugArray) {
if (plug == mFileAttr)
{
MPlug fileNamePlug(thisMObject(), plug);
MString fileName = fileNamePlug.asString();
}
return MPxNode::setDependentsDirty(plug, plugArray); }
Edit:
Just to clarify, reading plug value itself, plug.asString()
, it still holds the old value.
回答1:
If you take close look in doc you will see why you are not getting the updated value
"IMPORTANT NOTE: since the setDependentsDirty() method is called during dirty propagation, you must be careful not to perform any dependency graph computations from within the routine. Instead, if you want to know the value of a plug, use MDataBlock::outputValue() because it will not result in computation (and thus recursion). In general, the majority of {setDependentsDirty()} methods which users will implement should involve only fixed relationships. In the rare occurence where you need to look at plug values, please heed the warning with {MDataBlock::outputValue()} and use plugs which contain values which you know to be up to date prior to the start of dirty propagation. "
来源:https://stackoverflow.com/questions/38692288/dirtied-plug-still-has-the-old-value-during-setdependentsdirty