Godot 4 dev notes
Collection of tips found while making games with the Godot 4 game engine
These may not be the best solutions ever, but these are just the ones that worked for me
Preload all resources
When instantiating a scene (like a weapon, and enemy, anything) never load and instantiate, instead preload anything in an autoload class then use it when needed.
As an example, fo fire a bullet add an autoload script called res.gd (class Res)
with content like this:
var shuriken := preload(\"res://bullets/shuriken.tscn\")
var red_apple := preload(\"res://items/red_apple.tscn\") # preload all the ones you need
...
Then in the shooting script add this function:
func add_bullet(weapon_name, pos):
var bullet: Node = Res[weapon_name].instantiate()
bullet.position = pos
get_tree().root.add_child(bullet)
Spawn the bullet in this way:
add_bullet(\"shuriken\", player.position)