Widget missing when executing a redo on a custom node

Widget missing when executing a redo on a custom node

doble_de
Explorer Explorer
456 Views
5 Replies
Message 1 of 6

Widget missing when executing a redo on a custom node

doble_de
Explorer
Explorer

Hi,

I'm working on a custom node. It modifies the timeline color, setting a custom widget created in the postConstructor call.

This widget is deleted when the node is "deleted" using the following callbacks:

MSceneMessage.kBeforeNew

MSceneMessage.kBeforeImport

MSceneMessage.kBeforeOpen

MNodeMessage.addNodePreRemovalCallback

MDGMessage.addNodeRemovedCallback

All those callbacks run a function that deletes the widget and all the callbacks the node created.

When I delete the node, the callbacks and the widget are removed. But if I do a redo, I can see the callbacks are up again, but not the widget.

Wondering how can I create the widget again after a redo of the node happens, as the constructor and the postConstructor are not called.

Thanks,

David

0 Likes
Accepted solutions (1)
457 Views
5 Replies
Replies (5)
Message 2 of 6

jmreinhart
Advisor
Advisor

Could you run"MDGMessage::addNodeAddedCallback" in registerPlugin? and have that callback take care of triggering the creation of those callbacks, rather than having the postConstructor do it? That seems safer, since construction/destruction may not always line up with deletion and creation. 

 

 

0 Likes
Message 3 of 6

doble_de
Explorer
Explorer

Hi,

thanks for the reply. The problem with the callback is that I delete all the callbacks when the node is deleted. So when I do an undo, that callback is not called.

0 Likes
Message 4 of 6

jmreinhart
Advisor
Advisor
Accepted solution

To clarify, this is what I was imagining.

 

When Node is Created

jmreinhart_0-1665513813654.png

When Node is deleted

jmreinhart_1-1665514009469.png

When delete is undone

jmreinhart_2-1665514124732.png

 

 

This would work differently than what you have now because the constructor doesn't get called again when you "undo" since the C++ object remains constructed when you undo. But the nodeAddedCallback would get triggered on the initial node creation and on the redo.

0 Likes
Message 5 of 6

doble_de
Explorer
Explorer

Oh, sorry I didn’t read it properly and I was creating the nodeAdded callback inside the node, and not in the load plugin part.

That worked great, thanks a lot! And thank you for doing the diagram!

0 Likes
Message 6 of 6

jmreinhart
Advisor
Advisor

Yeah, it's a bit hard to convey in words. Glad it worked!

0 Likes