Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom nodes not working #112

Open
alicwyz opened this issue Mar 5, 2025 · 0 comments
Open

Custom nodes not working #112

alicwyz opened this issue Mar 5, 2025 · 0 comments

Comments

@alicwyz
Copy link

alicwyz commented Mar 5, 2025

Version:

UPBGE: 0.36
Logic Nodes: 2.3

Problem:

Custom nodes not appearing on the add menu after being imported

Description:

I was trying to code some custom OSC nodes to connect UPBGE to puredata (we were previously using python scripts with brick nodes, but that wasn't flexible enough or welcoming to beginners). But nothings seems to be working? Even the templates don't work.

If you try to import them they give "TypeError: Cannot create a consistent method resolution order (MRO)". Removing "bpy.types.nodes" from the class declaration fixes the issue, but still nothing happens and they don't appear anywhere? Is there some other way to add nodes?

Code:

  • My "OSC Send" node:
# save in ./bgelogic/nodes/my_custom_nodes.py

import bpy
import bge_netlogic
import socket


#Sockets
NLParameterSocket = bge_netlogic.basicnodes.NLParameterSocket
NLConditionSocket = bge_netlogic.basicnodes.NLConditionSocket
NLIntegerFieldSocket = bge_netlogic.basicnodes.NLIntegerFieldSocket
NLQuotedStringFieldSocket = bge_netlogic.basicnodes.NLQuotedStringFieldSocket


#Nodes
NLParameterNode = bge_netlogic.basicnodes.NLParameterNode
NLConditionNode = bge_netlogic.basicnodes.NLConditionNode
NLActionNode = bge_netlogic.basicnodes.NLActionNode


#Send OSC Message
class OSCSendNode(NLActionNode):
    #id
    bl_idname = "OSCSendNode"
    #Título do Node
    bl_label = "Send OSC Message"
    
    #Initialize inputs x outputs
    def init(self, context):
        NLActionNode.init(self, context)
        
        #Inputs 
        self.inputs.new(NLConditionSocket.bl_idname, "Condition")

        self.inputs.new(NLQuotedStringFieldSocket.bl_idname, "IP")
        self.inputs[-1].value = socket.gethostbyname(socket.gethostname())
        
        self.inputs.new(NLIntegerFieldSocket.bl_idname, "Port")
        self.inputs[-1].value = 5005
        
        self.inputs.new(NLQuotedStringFieldSocket.bl_idname, "OSC Address")
        self.inputs[-1].value = "/game"
        
        self.inputs.new(NLParameterSocket.bl_idname, "Data")
        
        #Outputs
        self.outputs.new(NLConditionSocket.bl_idname, "Done")
    
    #Define Cell
    def get_netlogic_class_name(self):
        return "osc_cells.OSCSendCell"
    
    #Input sockets
    def get_input_sockets_field_names(self):
        return [
            "condition",
            "ip",
            "port",
            "osc",
            "data"
        ]
    
    #Output sockets
    def get_output_socket_varnames(self):
        return ['DONE']
    

bge_netlogic.register_nodes("OSC", OSCSendNode)
  • My "OSC Send" cell:
# save to ./bgelogic/cells/my_custom_cells.py
# refresh imported nodes after changes have been applied to both custom cells
# and nodes

import bgelogic
import pythonosc.udp_client

ActionCell = bgelogic.ActionCell
ParameterCell = bgelogic.ParameterCell
LogicNetworkSubCell = bgelogic.LogicNetworkSubCell

class OSCSendCell(ActionCell):
    
    # Initializes the cell
    def __init__(self):
        ActionCell.__init__(self)
        
        #Inputs
        self.condition = None
        self.ip = None
        self.port = None
        self.osc = None
        self.data = None
        
        #Outputs
        self.DONE = LogicNetworkSubCell(self, self.set_output)
        
        #Internal
        self._done = False
        self._client = None
    
    #Ouput function
    def set_output(self):
        return self._done
    
    def evaluate(self):
        _condition = self.get_input(self.condition)
        if _condition is LogicNetworkSubCell.STATUS_WAITING:
            return
        
        _data = self.get_input(self.data)
        if _data is LogicNetworkSubCell.STATUS_WAITING:
            return
        
        _ip = self.get_input(self.ip)
        _port = self.get_input(self.port)
        _osc = self.get_input(self.osc)
        
        self._set_ready()
        
        if self.setup_server(_ip, _port):
            self._done = self.send_osc(_osc, _data)
    
    #Create OSC Server
    def setup_server(self, ip, port):
        if self._client is None:
            try:
                self._client = pythonosc.udp_client.SimpleUDPClient(
                    ip, 
                    port
                )
            except Exception as e:
                print(f"OSC Send Error: Could not create client - {e}")
                return False
        return True
        
    def send_osc(self, osc, data):
        try:
            # Send message with appropriate type handling
            self._client.send_message(osc, [data])
            return True
        except Exception as e:
            print(f"OSC Send Error: {e}")
            return False
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant