I have tangled myself up a bit!

If you watch the clip, I have this animation in a scene, placed in a main scene.
Imagine halfway through this animation, another section appears at the tip (still moving until the animation finishes), and repeats as if the thing was growing a new section several times. This is my end goal!

var newBone = preload("res://Src/Platforms/Bambone/BamboneTest.tscn").instance()
export var NumberOfIterations :int = 4
var CurrentIterations :int = 0

func _ready():
	pass
	
func _unhandled_input(_event):
	if CurrentIterations < NumberOfIterations:
		if Input.is_mouse_button_pressed(1) and not $BamboneTest/AnimationPlayer.is_playing():
			$BamboneTest/AnimationPlayer.play("Spawn_Point")
			CurrentIterations += 1
			print("Iteration ", CurrentIterations)
			get_tree().get_root().add_child(newBone)
			newBone.position = $BamboneTest/SpawnPoint.position
		else:
			pass

func _process(delta):
	print($BamboneTest/SpawnPoint.position)
	pass

The animation scene has a ‘spawn point’, where I want the new instance to appear, but it doesnt appear with this line….
newBone.position = $BamboneTest/SpawnPoint.position

though trying to check the position in the process part with the print statement, this does show the changing position co ordinates of the ’SpawnPoint’

The new instance seems to just replace the original animation, not add another one, and in the editor window scene tree remote part, only ONE instance seems to be made, despite trying to do several iterations, from a mouse click….

I know Im waaaaaay off the mark for getting this right, but Im now very stuck!

any help welcomed! 🙂

  • Not sure I totally understand expected behavior here, so this may not be what you're going for, but it sounds to me like every time the player clicks you want a new bone segment to extend from the previous one. If that's the case, I'd track whatever the last bone segment spawned was. So up top you'd have:
    onready var lastBone = $BamboneTest (you can of course type hint that, just not sure what node BamboneTest inherits from)

    Then replace all your $BamboneTest references in the script with lastBone (though you might need to also change things like $BamboneTest/AnimationPlayer to something like lastBone.get_node("AnimationPlayer"), not sure off the top of my head).

    Then probably use global position when adding the new node:
    newBone.global_position = lastBone.get_node("SpawnPoint").global_position

    And finally, after that update lastBone:
    lastBone = newBone

    Obviously don't have your project to test that so that might require some further tweaking, but hopefully it's close enough to be useful.

That script only creates one instance of BamboneTest. I'd try changing:
var newBone = preload("res://Src/Platforms/Bambone/BamboneTest.tscn").instance()
to
var boneScene = preload("res://Src/Platforms/Bambone/BamboneTest.tscn")
and then add
var newBone = boneScene.instance()
right before
get_tree().get_root().add_child(newBone)

    soundgnome

    Ha! I was wondering why only one (the same) instance was created despite each click supposedly creating a new one. This does put multiple instances in the main scene, thanks for that! Seems I was closer to getting this right than I thought!

    HOWEVER, I would need the second instance to start at the correct spawn point on the first instance, the third instance to start at the spawn point on the second instance etc etc....

    As these instances dont exist yet, how would I connect to the spawn points on each consecutive instance, the first one is already part of the main scene, the second one instanced from the code, spawns at the right place, but after that, nothing exists yet!

    Not sure I totally understand expected behavior here, so this may not be what you're going for, but it sounds to me like every time the player clicks you want a new bone segment to extend from the previous one. If that's the case, I'd track whatever the last bone segment spawned was. So up top you'd have:
    onready var lastBone = $BamboneTest (you can of course type hint that, just not sure what node BamboneTest inherits from)

    Then replace all your $BamboneTest references in the script with lastBone (though you might need to also change things like $BamboneTest/AnimationPlayer to something like lastBone.get_node("AnimationPlayer"), not sure off the top of my head).

    Then probably use global position when adding the new node:
    newBone.global_position = lastBone.get_node("SpawnPoint").global_position

    And finally, after that update lastBone:
    lastBone = newBone

    Obviously don't have your project to test that so that might require some further tweaking, but hopefully it's close enough to be useful.

      soundgnome

      Yes, you understood it! I just need it to work on a click for now, in reality, once the spawning stats, its a specific animation frame that triggers the next one to spawn and so on until the required number of iterations are met!

      This pretty much works as I need it! Thanks so much for the nudge!

      I just need to connect the animation player to do the spawning (I think), and, as the first few frames of the spawned object the postition will move, put that in the func _process. I should be able to figure that bit out!!