Programmatically disable WorldEnvironment

Godot Version

4.2.2.stable

Question

Simple question:
I have a node that has a WorldEnvironment attached.
In my _ready(), I tried:


$WorldEnvironment.set_process(false)

But unfortunately, this doesn’t disable the environment (which adds a glow effect to the Node). What is the correct way to turn this effect on/off programmatically?

$WorldEnvironment.environment=null
and
$WorldEnvironment.environment= load(path_to_environment_resource)

Hey! Setting the environment to null worked, but load doesn’t seem to re-enable.


func _ready():
	$WorldEnvironment.environment = null
	$WorldEnvironment.environment = load("res://scenes/letter.tscn::Environment_sg13e")

I got the resource path directly from the inspector. Does that look correct?

i never used it like this way, you can save the environment as a new file and really load the file from the saved path

I did that also, but still no luck:


$WorldEnvironment.environment = load("res://scenes/letter_glow.tscn")

The effect just doesn’t show.

this doesnt load the environment file, i mean the resource of the environment, not the scene

save the environment like this:
image
it should be named as new_environment.tres
then you just load the file from file path

Thank you, that did it!

1 Like

One more quick question:
When I load the resource, it effects every node of that type in the scene instead of just the one node that was selected with gui input. I tried “Make Local To Scene”, but that doesn’t seem to help.

For example, after a mouse click on a specific letter, I try:


letter_selector.get_child(pos).get_node("WorldEnvironment").environment = load("res://resources/letter_glow.tres")

But this changes every letter in the scene. Any idea?

i believe world environment is whole world, so it affects anything

Oh…would I have to accomplish this with a custom shader then? I guess that makes sense as it is called "World"Environment

from what i read it said entire scene, i havent tested if it also mean any canvas Layer’s layers also got affected by it.

what are you trying to do with the world environment btw?

usually from what i’ve seen people used world environment in 2d to add bloom effect or glowing for their laser

I’m trying to add a glow effect around a specific control within my scene, not the entire scene.

yes, can try shader for that, i’ve ever watched a tutorial for it with shader:

1 Like

Yup, thanks. I was able to code a shader that is okay, but thought naively it would be easier to use the WorldEnvironment node. Thanks for clearing that up