(SOLVED) Lag spike on first firing a bullet in debug

Godot Version

Godot 4.2.1


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()
	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?

Preload the bullet at the start of the game; do not use load.

onready var PlayerBullet = preload(“res://scene.tscn”)

tried it. the issue persists.

can you do a profiler and send screen shot of the spike


(is that what you wanted me to send? I didn’t do any profiling in Godot before…)

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.

1 Like

Turns out the issue was with the Renderer I was using (Compatibility). Works smoothly with either Forward+ or Mobile.

1 Like

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