0

I have created a setting item on the main screen in Godot 4, but I want to create a setting item to change the screen size in the settings, and I am having trouble getting it to work, even after looking at references and such.

What I was hoping to do is to have a setting screen and be able to change the screen size with the left and right cross keys, but I have already finished programming the cross keys.

What we tried was to use the ProjectSettings

ProjectSettings.set_setting("display/window/size/width", 1920)
ProjectSettings.set_setting("display/window/size/height", 1080)

I tried to write the above but it does not work. Is there a function to apply it?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Locu
  • 25
  • 4
  • Those project settings are only applied on launch. Channing them in runtime will not reflect any effect. – Theraot Aug 25 '23 at 01:08
  • Does this answer your question? [create custom window in godot](https://stackoverflow.com/questions/76921933/create-custom-window-in-godot) – Theraot Aug 25 '23 at 01:08
  • I looked at the questions you suggested, but could not figure out how to write the code. It says: "Call get_window() to get a Window object and set its position and size properties. Similarly, if you need to change the window mode, use the mode property of the Window object." but I understand get_window(), but I don't know how to change the size! – Locu Aug 25 '23 at 04:34
  • It is a property, you set the property. I have posted an answer. – Theraot Aug 25 '23 at 04:42

1 Answers1

0

In Godot 4, from a Node in the scene tree, you an get a reference to the Window it is in with get_window():

var window := get_window()

And it has a size property. A property, that you can set. In GDScript uou can either set it by component:

var window := get_window()
window.size.x = 1920
window.size.y = 1080

Or you can set a new size (which is what you would do in any other language). It is a Vector2i (as a look in the documentation would confirm):

var window := get_window()
window.size = vector2i(1920, 1080)

And, of course, you can do the whole thing in a single line:

get_window().size = vector2i(1920, 1080)

It does not get any simpler than than.

Theraot
  • 31,890
  • 5
  • 57
  • 86