0 votes

Hi!

Does anyone know how to use GDscript to enable/disable WorldEnvironment properties?

In particular, I was hoping to use setdofblurfarenabled to switch DOF on and off. Basically, I've set all parameters up in the inspector but I want to be able to toggle DoF on and off based on certain events. I thought it would be as simple as attaching a script to my WorldEnvironment node and using the setdofblurfarenabled(bool) inside it, but it clearly doesn't work like this. I can't find any tuts. Can someone help please...

in Engine by (422 points)

2 Answers

0 votes
Best answer
get_node("<RelativePathToNode>").environment.dof_blur_far_enabled = not environment.dof_blur_far_enabled

The get_node-part in front is only needed when the script is not attached directly to the WorldEnvironment-node. If you hover over a property in the Inspector, it will display the property name in a tooltip - use this to find out the right path for setting it from GDScript.

by (10,311 points)
selected by

The documentation needs some examples to avoid some mistakes.

My mistake, for example, was the case below:

My example:

Wrong: $WorldEnvironment.glowintensity = value
Correct$WorldEnvironment.enviroment.glow
intensity = value

I didn't think I would need to use "enviroment" after "WorldEnvironment".

I couldn't understand this from the documentation either.

As always, thanks to the Godot community for this amazing tool.

0 votes

I also had difficulty understanding how to change WorldEnvironment values in GDScript.
Seeing the answer you got, I understood (but it took me a while to realize) that in the case of WorldEnvironment, it's not enough to write in GDScript the name of the WorldEnvironment + ".attribute". To work, you need to write WorldEnviroment + enviroment + ".attribute".

My example:

Wrong:
$WorldEnvironment.glow_intensity = value

Correct:
$WorldEnvironment.enviroment.glow_intensity = value

I think the documentation could have some example of using WorldEnvironment to facilitate the learning of those who are learning GDScript (as is my case).

As always, thanks to the Godot community for this amazing tool.

ago by (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.