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

Fade-in, fade-out

Sometimes we just need tomething (any node) to fade-in and fade out, this can be easily done without setting an animation.

The effect works animating the transparency, and at the end the node is actually hidden.

If it was actually removed using queue_free(), it would be impossible to have it appear again with fadeIn()

func fadeIn(item, duration):
    item.visible = true
    item.modulate = Color(1,1,1,0)
    var fadeTween = self.create_tween()
    fadeTween.tween_property(item, "modulate", Color(1,1,1,1), duration)

func fadeOut(item, duration):
    item.modulate = Color(1,1,1,1)
    var fadeTween = self.create_tween()
    fadeTween.tween_property(item, "modulate", Color(1,1,1,0), duration)    
    fadeTween.tween_callback(func(): item.visible = false)

To use it just do like this:

fadeOut( get_node("item", 0.5) )