Bullet deleted after a certain time

Is there an easy way to delete a bullet after a certain time. I would like a bullet to be on screen for say 2 seconds then get deleted.

I would love this to be implemented into the fire bullet extension something like bullet lifespan.

I looked into various methods but couldn’t understand them. i know Time Delta is one way but I found this way too complicated.

The only way I could do it was using this code pretty easy but would like to know if there is a better way.

My Code

That method seems fine. It’s simpler than adding a timer or a tween set to destroy the object. IDK if one method is better than the other.

A built-in method for the Fire behavior would be nice. It could be based on time and/or distance.

1st of all what exactly you want
Bullet to disappear while it is still on screen?
OR it don’t be allowed to exist forever?

Cause if you only care for it to not exist forever
It would make more sense to delete it if its beyond camera borders
Where you need to check if X position of bullet is greater than CameraBorderRight()
And less than CameraBorderLeft()
Repeat it for top and bottom border on Y axis
And if so you delete bullet

MOST brain dead option is to simply check if distance from player is greater than some value by using condition distance between object inverting it and then setting distance you want

But this option would work for player and what about enemies?
So in that case solution with camera borders would be better

IF you want bullet just to exist for 2 sec
And you want to use time delta
You would need to give each bullet variable like some number variable
And subtract from that variable (or add) 1*TimeDelta() or maybe it was 1/TimeDelta() i do not remember
But that will add or subtract 1 each (depending on what you choose) second from that variable
And if you went with adding you could now check if value of variable is above 2
If you went with subtracting you can check if value of variable is below -2 and you have your 2 seconds there
BUT that is having for each bullet constantly adding or subtracting on each frame some value to/from variable

Other solution is to check current/device time simply by using Time(“min”) Time(“sec”)
Which will give you current device time
And when bullet is created you set that values to some variable of EACH of your bullets and check using condition compare two numbers
Bullet.Variable(Time) is greater than Bullet.Variable(Time)+2
You delete bullet
There is also TimeSinceSceneStart() or something like that maybe it was TimeSinceStart()
You can find it with autocomplete by just typing Time in expression
And you print that to variable and use same compare two numbers trick
OR even without using compare two numbers you simply check if value of variable is greater than variable+2 and so you delete bullet

Problem with TimeDelta() it works based on FPS so if your game runs at 30 FPS (due lag) or you have unlimited FPS set in properties
And someone runs your game at 144FPS then you do not get 1 each second
Ones with 30 fps will get 0,5 each second where ones with 144fps will get 1 each 0,25 sec

So all that said
Pick your poison

How I usually do that is use the “is on screen” behavior on the bullet. Then in the events I set it to where if the bullet is not on screen (with and extended border of 100) delete the bullet. If this is confusing, I could make a video showing it