The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+13 votes

I'm trying to implement a button in my menu which toggles fullscreen on and off.

Basically, I want clicks of the button to toggle the fullscreen property from Project Settings > Display > Window , but I can't figure out how to reference it.

I tried ProjectSettings.get_setting("size/fullscreen"), but it wasn't a correct reference.

I also notice that there's an OS.window_fullscreen, but I'm not sure if that's the same as the property listed in Project Settings.

I want to work with this property from Project Settings rather than get and set resolutions of the screen and viewport directly.

Any advice?

in Engine by (1,600 points)
retagged by

2 Answers

+25 votes
Best answer

As of Godot 3.0, you can just set OS.window_fullscreen to true in any script to enable fullscreen – no need to deal with the project settings manually. It will behave the same way as the project setting does.

Tip: If you want to toggle fullscreen, you can avoid using an if condition by setting OS.window_fullscreen to its inverted value:

if event.is_action_pressed("toggle_fullscreen"):
    OS.window_fullscreen = !OS.window_fullscreen
by (12,878 points)
selected by

Thanks. That inversion trick is very cool. Didn't know about it.

Thank You, this is a great answer!
I had to change it to the following, however:

if Input.is_action_just_pressed("toggle_fullscreen"):
    OS.window_fullscreen = !OS.window_fullscreen

The godot version I use is 3.0.2

All the best

In godot 3.2, you must use


as OS.window_fullscreen is read-only


OS.window_fullscreen = !OS.window_fullscreen works in v3.3.2.stable.official for me

Literally none of these solutions are working for me in version 3.4.3.stable, I have absolutely no idea what I could be doing wrong :/

This is just inside my Player script as I wasn't sure where else to put it. Other keybindings work fine in other functions within this script. I have the button set as the F key in Project settings just like the other keybindings.

func _ready(): = true 
    swordHitbox.knockback_vector = Vector2.DOWN 
    stats.connect("current_health_zero", self, "queue_free")
    OS.window_fullscreen = true
    if Input.is_action_just_pressed("toggle_fullscreen"):
        OS.window_fullscreen = !OS.window_fullscreen

What in the world am I doing wrong?? I've tried it without the OS.window fullscreen = true line, I've tried it with the Fullscreen checkbox checked and unchecked in the project settings, I've tried using different keybindings, and I've tried all of the above solutions.

_ready() is only called once, when the node enters the scene tree and is therefore not suitable for checking input events.

+2 votes

In Godot 4.x things seem to have changed slightly again, these functions have moved to the DisplayServer singleton. This worked for me:

func swap_fullscreen_mode():
    if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_MAXIMIZED:


by (44 points)

thank you for sharing this

@jeroenheijmans That isn't exactly a solution for true toggling though :/ I'm looking for a toggle loop that can store what the display mode was before toggling. This will allow players to set their display mode to whatever they want and if they hit the fullscreen button it will remember what to switch back to.

I've got it. This code (4.0.3 stable) will allow you to switch between exclusive fullscreen (value 4) and whatever was viewed previously to exclusive fullscreen. If the game started in exclusive fullscreen, there's a loop in there too for switching it to maximized (value 2):

#top of script
@onready var previous_window = DisplayServer.window_get_mode()
@onready var current_window = DisplayServer.window_get_mode()

#body of script
func _input(event):
    if Input.is_action_just_pressed("toggle_fullscreen"):
        current_window = DisplayServer.window_get_mode()
        if current_window != 4:
            previous_window = current_window
            if previous_window == 4:
                previous_window = 2
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.