Closes https://github.com/godotengine/godot/issues/40435 (cherry picked from commit cefca25796)
cefca25796