Need some help with timers

Hi all, I must be using timers incorrectly or something, maybe someone can help me find/understand what I am doing wrong. I am following a tutorial series on youtube where you create an apple tree using a timer to transition the tree from not having apples, to having apples. Once you interact with the tree and “pick” the apple. It plays an animation, and then after a couple of seconds it starts the timer once more.

It starts in ready with no apples and the timer after X seconds will change the state which in turn renders the apples on the tree. When I debug the game with print, I can see all the instances are supposed to be starting their timers. But what I am experiencing is, that it only actually starts the timer when it’s visible on screen. I don’t have it wrapped in a VisibleOnScreen or anything like that. Why would this be the case?

The script:

extends Node2D

@export var item: InventoryItem

var player = null
var state = "no_apples"
var player_in_area = false
var apple = preload("res://scene/apple_collectable.tscn")

func _ready():
	print("apple tree ready")
func _process(_delta):

	if state == "apples" and player_in_area and Input.is_action_just_pressed("interact"):
		state = "no_apples"

func _on_pickable_area_body_entered(body):
	if body is Player:
		player_in_area = true
		player = body

func _on_pickable_area_body_exited(body):
	if body is Player:
		player_in_area = false

func _on_growth_timer_timeout():
	print("apple_tree timer timeout", state)
	if state == "no_apples":
		state = "apples"

func drop_apple():
	var apple_instance = apple.instantiate()
	apple_instance.global_position = $Marker2D.global_position
	await get_tree().create_timer(1.5).timeout

And this is how the scene looks:

What have you set as the target node for the VisibleOnScreenEnabler2D? I wonder if it’s the parent pausing the process.

1 Like

OMW ok yeah I didn’t know that detail :laughing: :rofl: I thought that it would be any/all child nodes. It was set to the root node :rofl: Thank you!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.