@xyz said:
@dotted said:
... question when you set a script to an node already in a scene tree, does _ready() get called?
No, but stript's _init() will be called.
It doesn't appear that adding a script to a node after it is in the scene tree adds in ( its newly bound?) _ready() call.
Placing a break point has no effect.
var engine:ArmatureEngine = ArmatureEngine.new()
line2d.set_script(engine.get_script())
line2d.bone_chain = fiber
line2d.distal_chain = distal
...
func process(delta:float):
var K:Array = bone_chain
var D:Array = distal_chain
Solved by making Engine extend Node and simply adding it thus:
func _add_armature_engine(line2d:Line2D, fiber:Array, distal:Array):
if fiber.size():
var engine:ArmatureEngine = ArmatureEngine.new()
engine.bone_chain = fiber
engine.distal_chain = distal
line2d.add_child(engine)
func _remove_armature_engine(line2d:Line2D):
var node:Node = line2d.get_node_or_null('ArmatureEngine')
if node: node.queue_free()
It's a bit cleaner, as it is in effect a 'processing' node added on demand to do a job which is then removed when the task is over.
The animated line2d points are now used to calculate the transforms of the armature and the bones follow precisely the animated point movement.