ProjectSettings in Godot – Complete Guide

Welcome to this in-depth journey into the world of Godot 4 and its ProjectSettings class. If you’re a game developer or interested in becoming one, understanding the power behind Godot’s ProjectSettings is essential for creating robust and scalable games. As part of Godot 4, the newest iteration of the popular open-source game engine, the ProjectSettings class offers fantastic capabilities for streamlining game configuration and management. Get ready to unlock the full potential of your gaming projects by mastering this key feature.

What is the ProjectSettings Class?

The ProjectSettings class in Godot 4 is a cornerstone for developers looking to manage their game projects efficiently. It provides a centralized place to store and access globally-relevant variables, making it a versatile tool for setting up and tweaking behaviors at a project-wide level.

What is ProjectSettings Used For?

Imagine needing to adjust the resolution, control settings, or defining game-specific parameters. Instead of hardcoding these into various scripts, Godot 4 allows you to use ProjectSettings to keep such configurations in one access point. These settings can affect your game’s performance, appearance, and even its platform-specific behaviors, offering unparalleled convenience and flexibility.

Why Should I Learn About ProjectSettings?

Understanding ProjectSettings is beneficial because:

– It makes your game development process more organized and manageable.
– It allows for easy tweaks and configurations without scouring through code.
– You can define platform-specific overrides, essential for multiplatform development.
– It prepares you for larger, more complex projects where proper settings management is crucial.

This class is one of the first steps you can take towards creating games that are as scalable as they are enjoyable. So, let’s jump right in and start exploring ProjectSettings with practical examples and crucial insights!

CTA Small Image
FREE COURSES AT ZENVA
LEARN GAME DEVELOPMENT, PYTHON AND MORE
ACCESS FOR FREE
AVAILABLE FOR A LIMITED TIME ONLY

Accessing and Modifying Basic Settings

When working with Godot 4, you’ll often need to adjust settings that apply throughout your game. These can include window size, fullscreen mode, and name of the application. Let’s see how to access and modify some basic settings with the ProjectSettings class.

// Changing the window size
ProjectSettings.set_setting("display/window/size/width", 1280)
ProjectSettings.set_setting("display/window/size/height", 720)

// Setting the game to start in fullscreen mode
ProjectSettings.set_setting("display/window/fullscreen", true)

// Setting the application name
ProjectSettings.set_setting("application/config/name", "My Awesome Game")

To apply these settings, it’s typically done at the start of your game, for example, in the `_ready` function of your main scene’s script.

Storing and Loading Custom Game Settings

Aside from modifying basic settings, ProjectSettings can be used to store your own custom game settings like default player name, difficulty level, or controls remapping. The following examples show how you can write to and read from ProjectSettings with custom settings:

// Storing a default player name
ProjectSettings.set_setting("game/player/default_name", "PlayerOne")

// Retrieving the stored default player name
var defaultPlayerName = ProjectSettings.get_setting("game/player/default_name")

// Storing a difficulty setting
ProjectSettings.set_setting("game/difficulty", 2)

// Accessing the difficulty setting you just set
var gameDifficulty = ProjectSettings.get_setting("game/difficulty")

These settings would then be used throughout your game to ensure a uniform experience based on user preferences or game defaults.

Saving and Loading Project Settings

Godot 4 allows you to save any changes made to ProjectSettings so that they persist between sessions. Let’s take a look at how this is done and how you can load these saved settings upon game start.

// Saving changes to the project settings
ProjectSettings.save()

// This code would generally go into a function that handles game exiting or settings changes

When your game is launched, Godot will automatically load all settings, but if you’ve made changes during runtime and saved them, you’ll want to ensure the current session reflects these updates.

Handling Platform-Specific Settings

Modern game development often requires your game to be compatible with different platforms, such as Windows, MacOS, or mobile devices. Godot’s ProjectSettings allows you to handle platform-specific settings seamlessly.

// Setting the window size differently for mobile platforms
if OS.get_name() == "iOS" or OS.get_name() == "Android":
    ProjectSettings.set_setting("display/window/size/width", 960)
    ProjectSettings.set_setting("display/window/size/height", 540)

// Overriding on OS-specific basis
if OS.get_name() == "Windows":
    ProjectSettings.set_setting("application/config/name", "My Awesome Game Windows Edition")

Note that these settings can be set dynamically at runtime based on the OS. This can be part of your game’s initialization script to make sure the settings apply before the game scenes start running.

Remember to save these settings only if they need to persist between sessions; otherwise, just setting them during startup will suffice for session-specific configurations. Stay tuned for further parts of our tutorial where we’ll continue exploring the depth of Godot 4’s ProjectSettings class!Great, let’s delve deeper into the capabilities of the ProjectSettings class in Godot 4. As your project evolves, you’ll find that managing user preferences, export settings, and even handling input maps becomes increasingly important.

Let’s explore some practical applications of ProjectSettings with hands-on examples.

Managing User Preferences

User preferences are settings that players might want to change, such as volume or custom key bindings. Here’s how you can use ProjectSettings to handle these aspects.

// Setting a default volume level
ProjectSettings.set_setting("user/audio/volume_master", 0.5)

// Changing the volume in-game
ProjectSettings.set_setting("user/audio/volume_master", newVolumeLevel)

Storing and retrieving user’s preferences is straightforward. To access the user’s preferred volume when starting the game or during gameplay, simply use:

var masterVolume = ProjectSettings.get_setting("user/audio/volume_master")

Export Settings and Presets

Export settings can be particularly complex, with various presets for different platforms. With ProjectSettings, specifying these settings programmatically is manageable.

// Setting up an export preset for Android
ProjectSettings.set_setting("export/android/custom_package/release", "path/to/your/release.apk")

// Specifying orientation for mobile devices
ProjectSettings.set_setting("export/android/screen/orientation", "portrait")

// Changing an HTML5 export setting
ProjectSettings.set_setting("export/html/custom_html_shell", "path/to/custom_shell.html")

Each platform has its own export settings, which you can modify according to your needs. These settings can be adjusted before you trigger the actual export process from within editor or in an automated build pipeline.

Handling Input Maps

Another powerful feature of ProjectSettings is the ability to dynamically define and modify Input Maps. This is handy for customizing controls, remapping keys, or adding support for additional input devices.

// Adding a new action
ProjectSettings.set_setting("input/ui_accept", [{"deadzone": 0.5, "events": [], "device": -1}])

// Mapping 'ui_accept' action to the Enter key
var enterKey = InputEventKey.new()
enterKey.scancode = KEY_ENTER
ProjectSettings.action_add_event("ui_accept", enterKey)

Once you define actions, accessing them in your code is done through the Input class, like so:

if Input.is_action_just_pressed("ui_accept"):
    print("Action accepted!")

It’s important to note that any changes made to Input Maps during runtime will not save automatically. To save these changes, you’ll have to call:

ProjectSettings.save()

Dynamic Configuration During Runtime

Sometimes, you might need to change configurations based on the game’s runtime conditions. Dynamic configuration allows you to adjust to different scenarios, such as difficulty levels, without restarting the game.

// Adjusting maximum enemies on screen based on difficulty
ProjectSettings.set_setting("gameplay/difficulty/max_enemies", currentMaxEnemies)

By integrating these dynamic settings within your gameplay logic, your game will be able to seamlessly respond to changes made in the ProjectSettings. This feature enables you to not only make on-the-fly adjustments but also test different configurations quickly during development.

ProjectSettings in Godot 4 creates a robust backbone for managing your game’s configuration in a centralized and streamlined manner. With the ability to tweak settings dynamically and save them for future sessions, you’re well-equipped to build games that can easily adapt to a variety of needs and enhance user experience. These foundational examples serve as a starting point for leveraging the power of ProjectSettings in your Godot 4 projects. Stay tuned for further advanced uses and optimization tips!As we dive into more advanced uses of the ProjectSettings class, we will be looking at various scenarios where ProjectSettings can significantly improve our game development workflow in Godot 4. This includes handling localization setups, adjusting physics settings, and managing network configurations.

Localization and Internationalization

Godot 4 makes it easier to prepare your game for a global audience by allowing the management of localization settings via ProjectSettings.

// Setting the default locale
ProjectSettings.set_setting("locale/translation_remaps/Default", "en")

// Add a localization remap to replace in-game text based on locale
ProjectSettings.set_setting("locale/translation_remaps", {
    "en": "res://locales/en.csv",
    "es": "res://locales/es.csv",
    "fr": "res://locales/fr.csv",
})

Localization and internationalization are crucial for reaching a broader audience, and Godot’s ProjectSettings class gives you programmatic control over these aspects.

Adjusting Physics Settings

Physics settings can have a significant impact on the feel and realism of your game. With Godot, you can tweak these settings to create the perfect balance for your gameplay. See how some of the physics settings can be adjusted.

// Changing the gravity value
ProjectSettings.set_setting("physics/3d/default_gravity_value", 9.8)

// Adjusting the default physics frames per second
ProjectSettings.set_setting("physics/common/physics_fps", 60)

// Setting up the physics layer names
ProjectSettings.set_setting("layer_names/3d_render/0", "Player")
ProjectSettings.set_setting("layer_names/3d_render/1", "Enemy")
ProjectSettings.set_setting("layer_names/3d_render/2", "Interactive")

Setting proper physics configurations can be crucial for fine-tuning movement and collision detection in your game.

Network Configuration for Multiplayer Games

For networked multiplayer games, it’s important to have the ability to configure various network properties. Godot’s ProjectSettings allows developers to set up these settings with ease.

// Setting the network multiplayer poll mode
ProjectSettings.set_setting("network/multiplayer_poll_mode", ProjectSettings.POLL_MODE_ALWAYS)

// Defining the default RPC mode
ProjectSettings.set_setting("network/multiplayer_rpc_mode", ProjectSettings.RPC_MODE_DISABLED)

// Configuring custom layers for multiplayer visibility optimization
ProjectSettings.set_setting("network/layers", {
    "layer1": "res://scenes/layer1.tscn",
    "layer2": "res://scenes/layer2.tscn"
})

Adjusting network settings can significantly reduce latency and improve the overall player experience in networked games.

Customizing Audio Settings

Custom audio settings can be a game-changer for creating an immersive gaming experience. Below are examples of managing audio configurations through ProjectSettings.

// Set the default bus layout for the audio server
ProjectSettings.set_setting("audio/bus_layout", "res://audio/default_bus_layout.tres")

// Changing specific bus volumes
ProjectSettings.set_setting("audio/buses/1/vol_db", -10)
ProjectSettings.set_setting("audio/buses/2/vol_db", -5)

// Toggle effect processing on a bus
ProjectSettings.set_setting("audio/buses/1/effects/1/bypass", false)

Managing audio settings, including volume levels, bus configurations, and effects, can elevate the audio experience of your games.

Conclusion

ProjectSettings in Godot 4 gives developers an enormous amount of flexibility and control over their game’s settings and configurations. We have explored how to programmatically tweak localization, physics, network, and audio settings to better suit your game’s specific needs.

Remember, invoking the ProjectSettings.save() function is essential if you want these changes to persist across game sessions. Through these examples, you should now have a thorough understanding of how to utilize the ProjectSettings class to fine-tune your Godot games.

As you become more familiar with the variety of options available in Godot’s ProjectSettings, you can streamline your development process and create games that are more dynamic, adjustable, and most importantly, tailored to provide the best possible experience for your players. Keep exploring and experimenting with ProjectSettings, and you’ll unlock even more potential for your gaming projects.

Continuing Your Game Development Journey with Godot

If you’ve enjoyed exploring the capabilities of the ProjectSettings class in Godot 4 and are eager to keep learning, we have just the resources to help you continue your journey. As a next step, we highly recommend our Godot Game Development Mini-Degree, a comprehensive set of courses designed to take your skills to the next level.

Our mini-degree covers a variety of crucial topics such as 2D and 3D game development, gameplay mechanics, UI systems, and building a diverse portfolio of Godot projects. Whether you’re a beginner or someone with a bit of experience, our curriculum is tailored to suit a range of learning needs. The Godot engine offers an approachable and powerful platform for crafting engaging games, and with our collection of courses, we’re here to guide you every step of the way.

Looking for a broader perspective on what you can achieve with Godot? Feel free to browse our complete selection of Godot courses. Zenva provides a flexible learning experience that allows you to study at your own pace and gain the skills needed to make an impact in the game development industry. So why wait? Start building your dream games with Godot and Zenva today!

Conclusion

Mastering ProjectSettings in Godot 4 is just the beginning of the incredible journey in game development that awaits you. Armed with the knowledge to control game configurations, manage preferences, and tailor interactions across various platforms, you’re already on the path to bringing imaginative and polished games to life. But why stop here? There’s a whole universe of development techniques and best practices out there, and we’re excited to help you discover each and every one of them.

With our Godot Game Development Mini-Degree, you’re not just learning – you’re creating, experimenting, and pushing the boundaries of what’s possible. Whether you dream of building the next indie hit or simply love the thrill of bringing interactive worlds to life, Zenva is here to fuel that passion. So take the next step, and let’s build those dreams into reality, together!

FREE COURSES
Python Blog Image

FINAL DAYS: Unlock coding courses in Unity, Godot, Unreal, Python and more.