+12 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,597 points)
retagged by

1 Answer

+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,725 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(): 
    animationTree.active = 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.

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.