• Godot Help
  • cant toggle fullscreen with ingame button

hey this is a pretty short piece of code that should just work but every time I try it says Cannot find member "window_fullscreen" in base "OS". or Static function "set_window_fullscreen()" not found in base "OS".

this is my code:

func _on_fullscreen_button_pressed() -> void:
	OS.set_window_fullscreen(!OS.window_fullscreen)
  • This is how you would do it in Godot 3.x:

    func toggle_fullscreen():
        OS.window_fullscreen = not OS.window_fullscreen

    In Godot 4.0:

    func toggle_fullscreen():
    	if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_WINDOWED:
    		DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
    	else:
    		DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)

This is how you would do it in Godot 3.x:

func toggle_fullscreen():
    OS.window_fullscreen = not OS.window_fullscreen

In Godot 4.0:

func toggle_fullscreen():
	if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_WINDOWED:
		DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
	else:
		DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)

    cybereality

    oh my god thank you!!!, I've looked at multiple sources from multiple dates and even tried chat.gpt and all of them have been telling me to write what i wrote

    cybereality To be honest, I don't know why the original code doesn't work. It should. But the other way works fine.

    Because godot is multi window capable now.

    cybereality To be honest, I don't know why the original code doesn't work. It should. But the other way works fine.

    Maybe because window_fullscreen is no longer a property of OS object (see doc) which explains the issue reported by @lancasterfudgel2020 (Cannot find member "window_fullscreen" in base "OS". or Static function "set_window_fullscreen()" not found in base "OS")