Yes - that's the expected result - original nodes leave, and the subdivided nodes keep generating until the 5th iteration, where they all get removed.
What you now have to do is set up each individiual node to connect the signal "mouse_entered" to the function "subdivide". Also - make sure you duplicate the shape of each Clone.get_node("CollisionShape2D").shape
as right now, you only duplicate when you make the Stamp
, meaning 4 objects are sharing the same shape at any given time.
Signal connections with code work like this:
Node .connect( "signal from node", recieving node, "receiving function", [ array of binds ], Connection method)
What you need is to have the original node connect it's signal directly to the subdivide function, while passing a bind containing it's own reference.
$StaticBody2D.connect("mouse_entered", self, "subdivide", [$StaticBody2D], CONNECT_ONESHOT)
(The connection method here doesn't seem to be needed, but I'm paranoid with the connection here).
When the mouse enters the StaticBody2D, it will fire the function subdivide, and pass the bound value of the reference to the StaticBody2D.
This same connection method needs to be applied to each generated node as well:
Clone.connect("mouse_entered", self, "subdivide", [Clone], CONNECT_ONESHOT)