Custom Node not calling socket_value_update?

Hello everyone. I am writing a Python addon with some custom nodes. Everything is going pretty well. I’ve got custom init, draw, and update functions working as they should. However, I can’t seem to get socket_value_update to call. I have added it to my node class with the correct signature

def update(self):
    print ("updating due to topology change...", type(self).__name__)
    #this one is called
def socket_value_update(self, context):
    print ("updating node...", type(self).__name__)
    #this one is not called

When I edit the node connections, update() is called, as expected. When I edit node socket values, however, socket_value_update() is not called. Am I doing something wrong? Is this a bug? I can hack around this for now…

EDIT: not sure I can hack around this, actually :sob: pls help meee

Any help would be appreciated. I promise you’ll like what I’m creating when you see it :wink:

1 Like

I have looked in Sverchok, Sorcar, LuxCore, Modular Trees… I can’t find any evidence of this function being used out in the wild. But I really need it! Well, I need it for pretty code :cry:. I tried to look inside of Blender’s repo but didn’t know where to look and couldn’t find anything except a couple lines defining the function in Diffusion’s search.

I even had a look through Animation Nodes and couldn’t find it, but still, do you know anything about this, @jacqueslucke ? Have I encountered a bug… or is this function just not implemented, despite it being in the documentation?

Not sure about this function. Can check that tomorrow.

Animation Nodes does not use the builtin socket types, but defines its own. This allows it to define custom update callbacks.

1 Like

Do custom callbacks require modifications to Blender? I’m willing to do something like that if I have to. Could make my node-system more flexible.

Thanks for the reply :slight_smile:

You can define your own socket types in an addon, there is no need to modify Blender itself.

I’ll have to have a look at animation nodes’ code, then.
I have custom socket types, but I have no idea how to query if there’s been a state change and then call an update. I tried adding something like that to a draw function to hack around the current issue, but it created an error. I suppose it isn’t really necessary to have everything update live, since I can re-calculate all the values in the ExecuteNodeTree operator, but it will simplify things for me if I can just keep them updated all the time.

I think the existence and proper functioning of socket_value_update is good for making Blender’s custom node-trees easy to develop for. Node Trees are great for making mockups. I want to use the simplest approach for now, once I know if my idea will work, then I can organize my code and do things according to best practices.

When you have custom sockets with properties already, then you can just add the update callback where you define the property.

class MySocket(bpy.types.NodeSocket):
    my_socket_value: FloatProperty(update=my_update_callback)

This seems to work very well: nope, it causes infinite recursion.

def update_socket(self,context):
    except AttributeError:
        print ("this node has no update function")
    # return self

… but then I have to define a custom socket for every socket, even when Blender’s NodeSocketStandard sockets would work (Try not to re-invent the wheel, right?). This may end up being the right thing to do, anyways. But this is a hack, pure-and-simple! It’s a functional and relatively clean hack, though. It also allows me to pass context in when Node.update()(for node graph topology changes) only gets self.

Anyways, this solves my actual problem, but it leaves the original issue… the callback function that never calls. I think this is a bug. Do you mind if I file a report or do you want to investigate it a little first? I hate filing superfluous bug reports with the tracker already so packed.

Thanks again!

Edit: I’m an idiot. Of course calling an update function can modify the values and then call the update function and then modify the values and then call the update function…
Anyways, the problem is solved by updating each node before reading the tree. Still it would be nice to be able to call the update when the changes occur, as that is the most straight-forward way to conceive of things.