Godot Version
4.0
Question
Hi
I have a simple Script that i attached to my “Banana” 2dArea.
The “Collection” of the banana runs smoothly and 2 new bananas are spawned. but it seems that in the new instances the script is not executed.
I would expect “banana ready” to be printed if the bananas are instanciated.
When I instanciate a scene, do the scripts not also get instanciated?
extends Area2D
# Called when the node enters the scene tree for the first time.
var banana_scene = preload("res://scene/banana.tscn")
var rng = RandomNumberGenerator.new()
# get screen size
var screen_size = get_viewport_rect().size
@onready var anim = $BananaSprite
func _on_body_entered(body:Node2D):
print("body entered")
if body.name == "CharacterBody2D":
anim.play("collect")
for i in range(2):
var new_banana = banana_scene.instantiate()
new_banana.position = Vector2(rng.randf_range(0, 1000), rng.randf_range(0, 1000))
get_parent().add_child(new_banana)
print(get_parent().name)
await anim.animation_looped
print("banana collected")
func _on_banana_sprite_animation_looped():
if anim.animation == "collect":
queue_free()
func _ready():
print("banana ready")
