Update callback for compositor node socket

Hey,
I am working on a custom compositor node but I am having a problem when I want to change the node behavior based on the input socket value. I have some properties such as:

py.props.FloatProperty(name="Value", description="Trololo..",default=0.0, update=update_effect)

Those can call the update function on the value change. I believe that sockets can’t do that when having something like this:

self.node_tree.inputs.new("NodeSocketFloat", "Start")

I can however read the socket’s value and use it in the update function. The problem is that the node only get’s updated when a property changes.

Why do I use socket and not all properties? I want to be able to link the value from different nodes in a similar way how for example Transform node works to be able to use things like tracking output etc. Transform node has all sockets and is updating when the values change there.

Is there any way to solve this?
Thanks for reading!

The best way to do this is to change the behaviour with nodes and not with python (i.e. MathNode>if val greater than x > output a different part of the node_tree).

The reason is that you don’t have access to the values that flow from nodes to nodes. Those only exist when the nodetree is being executed by the compositor engine, and Python cannot access this data.

Hey Secrop, many thanks for the reply. You have helped me before on stack regarding custom compositor nodes.

Actually I can access them like (the problem is just the update):
self.inputs['Start X'].default_value

So sockets are meant to affect only the node’s node tree right? The thing is that I have some python logic that generates an image and I want to use those socket inputs there. I can add some button to refresh the effect but it wouldn’t work when rendering animations etc while changing the socket values.

Pity that I cannot connect another node’s output to a property.

The defaul_value is used only when the socket is unlinked. If the socket is linked, the value comes from another node, and here you don’t have access to it.

But you still have the option to track events in the editor, using the update() function, which is called whenever something in the editor changes… it’s clumsy and you still don’t have access to the input value… (unless is something simple as a value node, which then you can get its default_value).
If it’s just to check if the default_value changes, you can use socket_value_update().

Ah you are right! I didn’t notice that it doesn’t work when the socket is linked to another node.
Hmmm I guess checking the links connected to the socket and trying to read the output value of the connected nodes wouldn’t work either.

By the way which update function do you mean? I have tried this one but seems to work only when the socket is linked/unlinked but not on value change.

I mean this one:
https://docs.blender.org/api/blender2.8/bpy.types.Node.html#bpy.types.Node.socket_value_update

I think there was a bug in this call… don’t remember if it was fixed.
I haven’t had anytime time lately to do anything in Blender… so I’m not “updated” to the last changes in the source.

I see. I’ll see what I can do with it and reply here If I solve it. Thanks for your help!