Set timer wait_time in frames?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Afely

Basically, I want to wait 40 frames and then delete a node. Is there a way to do this with the timer node, or would I have to use another method?

:bust_in_silhouette: Reply From: AndyCampbell

I believe Timer can only be triggered with a time.

Maybe you can calculate the required time from the current duration of a frame. If you used delta inside _physics_process(delta) that should be a consistent value, or if you call it from _process(delta) delta that will vary based on current frame rate. I’m not sure about your use case but that should get you reasonable accuracy

If you really need an exact number of frames, it’s probably easiest to just have your node initialise a counter when it is created and increment the counter each frame until it hits your target, then call your delete function.

extends Node (or whatever your node script extends)

var frame = 0
const max_frames = 40

func _process(delta):
	frame +=1 
	if frame == max_frames:

Yeah, that’s the solution I came up with. It didn’t seem very efficient though, so I just wanted to make sure I wasn’t overlooking some better method. Thanks, though

Afely | 2020-11-15 16:59