I need a instance of a class that is shared among nodes (singleton). Problem is I can't call the methods of it. Here is the problem isolated:
import bpy
from ... base_types.node import AnimationNode
class Singleton:
def __call__(self):
return self
def bar(self):
print("bar")
class Foo(bpy.types.Node, AnimationNode):
bl_idname = "an_Foo"
bl_label = "Foo"
singleton = None
def create(self):
self.singleton = Singleton()
def execute(self):
self.singleton.bar()
Traceback (most recent call last): File "C:\Users\clankill3r\AppData\Roaming\Blender Foundation\Blender\2.77\scripts\addons\animation_nodes\execution\main_execution_unit.py", line 38, in executeUnit exec(self.executeCodeObject, self.executionData, self.executionData) File "execution: 'NodeTree'", line 4, in File "C:\Users\clankill3r\AppData\Roaming\Blender Foundation\Blender\2.77\scripts\addons\animation_nodes\nodes\serial\foo.py", line 24, in execute self.singleton.bar() AttributeError: 'NoneType' object has no attribute 'bar'