Change worldenvironment node blur with code?

Godot Version

4.2

Question

hi, im trying to make the background blury when i have a menu open. i have a basic menu made and working but i can’t get the background to blur. i know there’s a setting in the worldenvironment node that dose that but i can’t find anyway to set it with code. is there any way to change the near distance blur setting in the worldenvironment node using code?
help

camera_attributes.dof_blur_near_distance

Usually it’s the resrource name and then the property name. You can drag & drop them into the code to generate the correct name automatically (not the full path though…)

still didn’t work :confused: i gotta be missing something, bc even tho it didn’t work it didn’t give any errors either. im still vary knew to code and godot so i wouldn’t be surprised if im just missing something painfully obvious. ill post my code here like i should have at the start.

extends Node

@onready var ui = $“…”
@onready var blur = $“…/…/environment/sky”

func _process(_delta):
if Input.is_action_just_pressed(“esc”):
if !get_tree().paused:
stop()
else:
start()

func start():
ui.visible = false
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
get_tree().set_deferred(“paused”, false)
environment.set(“camera_attributes.dof_blur_near_distance”, 0.1)

func stop():
ui.visible = true
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
get_tree().set_deferred(“paused”, true)
blur.set(“camera_attributes.dof_blur_near_distance”, 100)

Well setting it like this should work:
your_world_environment_node.camera_attributes.dof_blur_near_distance = 0.1

I’m not a big fan of using set() because it silently fails amongst other reasons, so not sure how to make it work with it.

edit:
here it seems like you’re trying to set it on the sky resource, not on the environment node itself:

thanks this worked! <3

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.