I made a simple bullet firing mechanism for a game, but every time I launch the debug environment, there’s a big lag spike upon first firing the bullet.
# Player.gd
@onready var PlayerBullet = load("res://player_bullet.tscn")
...
func shoot():
var b = PlayerBullet.instantiate()
owner.add_child(b)
b.transform = $PlayerHitbox.global_transform
The game freezes for about 0.5s upon first calling the shoot() function in _physics_process(), but after that the framerate is stable as ever. How do I get rid of this lag spike?
Ok, so I recommend looking up some stuff about the profiler and seeing what process is taking so long that it’s spiking. and try to rewrite it so that it uses less processing time.