Best way to delete node specific callbacks

Best way to delete node specific callbacks

morinnicolas8944
Advocate Advocate
1,931 Views
2 Replies
Message 1 of 3

Best way to delete node specific callbacks

morinnicolas8944
Advocate
Advocate

I have a node that uses MNodeMessage::addAttributeChangedCallback in postConstructor to recompute some internal values when its attributes change.

Since there is a separate callback registered for each instance of the node, I want to remove it when the node is deleted.

To do so, I also added a callback with MNodeMessage::addNodePreRemovalCallback which deletes all the callbacks registered for this instance of the node.

 

This works well when the node is deleted manually, but I noticed that the pre-removal callback is not called when I open a new scene so the callback stays around and is causing problems.

 

What would be the proper place to remove the callback?

 

I found this unanswered post which might be related.

https://forums.autodesk.com/t5/maya-programming/callbacks-for-node-removal-no-longer-triggered-when-...

0 Likes
Accepted solutions (2)
1,932 Views
2 Replies
Replies (2)
Message 2 of 3

cheng_xi_li
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

Maybe MSceneMessage is better, it has scene callbacks for new/open/saving etc...

 

Yours,

Li

Message 3 of 3

morinnicolas8944
Advocate
Advocate
Accepted solution

Thanks. I was hoping for something more general, but I guess there is no easy way to handle this.

 

In the end, I used callbacks for MSceneMessage::kBeforeNew and MSceneMessage::kBeforeOpen to detect when the current file is being closed and its nodes are being deleted. And I used MNodeMessage::addNodePreRemovalCallback to detect when a node is being deleted explicitly. Whenever one of those callbacks gets called, I delete all the callbacks for the current node.

 

I just hope this is covering all the possible scenarios where a node is removed from the active scene. It would have been nice if all cases had been covered by MNodeMessage::addNodePreRemovalCallback or some other general-purpose deletion callback.

0 Likes