0 votes

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?

in Engine by (110 points)

1 Answer

0 votes

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 physicsprocess(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:
by (541 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.