0 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?

asked May 12, 2018 in Engine by Diet Estus (1,453 points)
retagged May 12, 2018 by Diet Estus

1 Answer

+6 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
answered May 12, 2018 by Calinou (5,141 points)
selected May 12, 2018 by Diet Estus

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

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 How to use this Q&A? before posting your first questions.