WorldEnvironment/environment

Godot Version

4.7 Stable

Question

Can someone help me with changing the brightness in WorldEnviornment because it keeps on saying: Brightness: Invalid access to property or key ‘environment’ on a base object of type ‘WorldEnvironment’.

	WorldEnvironment.environment.adjustment_enabled = true
	WorldEnvironment.environment.adjustment_brightness = $"Settings Menu/BritghtnessS @ Brightness()lider".value

You’re trying to access WorldEnvironment, which is a class that doesn’t have a static property named environment, hence the error.

It’s hard to suggest a proper way to fix this error without seeing the whole script, so please share the whole script.

You should be trying to access the environment property on the instance of WorldEnvironmentclass.

extends Control

@onready var Player = get_node(“/root/Main/Player”)
@onready var play = $Play
@onready var settings = $Settings
@onready var MMCam = $“Main Menu Cam”
@onready var SBATM = $“Settings Menu/BackToMenu”
var inSettings = false
func _ready() → void:
SBATM.pressed.connect(backToMenu)
$“Settings Menu/BritghtnessSlider”.drag_started.connect(Brightness)
if Player.get_meta(“InMM”):
var camera_node = Player.get_node(“CharacterBody2D/Camera2D”)
if camera_node:
camera_node.enabled = false
var main_menu_cam = get_node(“Main Menu Cam”)
if main_menu_cam:
main_menu_cam.enabled = true

func _input(event: InputEvent) → void:
if Input.is_action_pressed(“Interact”):
if Player.get_node(“CharacterBody2D”).global_position.distance_to(play.global_position) < 500:
if inSettings == false:
print(“play”)
if Player.get_node(“CharacterBody2D”).global_position.distance_to(settings.global_position) < 500:
if inSettings == false:
inSettings = true
MMCam.global_position = Vector2(4500, 41)

func backToMenu():
inSettings = false
MMCam.global_position = Vector2(0, 41)

func Brightness():
WorldEnvironment.environment.adjustment_enabled = true
WorldEnvironment.environment.adjustment_brightness = $“Settings Menu/BritghtnessS @ Brightness()lider”.value

Here’s the whole script, it’s for a main menu system. If you have any other suggestions, please tell me.

Please format the code properly, it’s unreadable in this form. See Posting guidelines in #Help channel

extends Control

@onready var Player = get_node("/root/Main/Player")
@onready var play = $Play
@onready var settings = $Settings
@onready var MMCam = $"Main Menu Cam"
@onready var SBATM = $"Settings Menu/BackToMenu"
var inSettings = false
func _ready() -> void:
	SBATM.pressed.connect(backToMenu)
	$"Settings Menu/BritghtnessSlider".drag_started.connect(Brightness)
	if Player.get_meta("InMM"):
		var camera_node = Player.get_node("CharacterBody2D/Camera2D")
		if camera_node:
			camera_node.enabled = false
		var main_menu_cam = get_node("Main Menu Cam")
		if main_menu_cam:
			main_menu_cam.enabled = true

func _input(event: InputEvent) -> void:
	if Input.is_action_pressed("Interact"):
		if Player.get_node("CharacterBody2D").global_position.distance_to(play.global_position) < 500:
			if inSettings == false:
				print("play")
		if Player.get_node("CharacterBody2D").global_position.distance_to(settings.global_position) < 500:
			if inSettings == false:
				inSettings = true
				MMCam.global_position = Vector2(4500, 41)

func backToMenu():
	inSettings = false
	MMCam.global_position = Vector2(0, 41)

func Brightness():
	WorldEnvironment.environment.adjustment_enabled = true
	WorldEnvironment.environment.adjustment_brightness = $"Settings Menu/BritghtnessS @ Brightness()lider".value

Some of the lines are to long to fit on one line so they’re split, I couldn’t find a work around, sorry.

You don’t have anywhere in your script a reference to the instance of the WorldEnvironment Node, which you need in order for this to work.

Similarly to how you created these references:

@onready var Player = get_node("/root/Main/Player")
@onready var play = $Play
@onready var settings = $Settings
@onready var MMCam = $"Main Menu Cam"
@onready var SBATM = $"Settings Menu/BackToMenu"

Sorry for bothering you because I figured out that WorldEnvironment is a totally different Node. I figured out what I needed to do, but thanks for trying to help me.