About Store Forum Documentation Contact



Post Reply 
Environment - Setting through code
Author Message
Dwight Offline
Member

Post: #1
Environment - Setting through code
Hi there,

Having some difficulty in setting the environment parameters through code. In the InitGame() function, whenever I do this, it works as expected:

Code:
if(Game.World.settings().environment)
   {
      Game.World.settings().environment->set();
      
      // Load the settings from the editor into the env_World_outdoor Environment
      env_world_outdoor.get();
      env_world_outdoor.fog.density = 0.02523040f; env_world_outdoor.fog.set();
      env_world_outdoor.set();
      
   }

env_world_outdoor is an object of class "Environment". How would I go and update this setting during runtime? My idea is as follows, something along these lines:

Code:
if (g_hour > 20 && g_hour < 5) // g_hour is current hour of the day
{
     env_world_outdoor.fog.density = 0.035f; env_world_outdoor.fog.density.set();
}

Putting the check in the update loop did not give the expected results. Any help is greatly appreciated!
10-22-2020 05:43 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #2
RE: Environment - Setting through code
I was confused a while ago about the same topic, the environment is just a holder of variables, you need to either call set() so those variables are pushed to the right settings in the engine, or push it yourself manually

set / get
void set (); // apply these settings to graphics (this will call 'set' on all members of this class)

Or like i said you can go to the members in that class and call specific set() ( you are calling density set() ?)
(This post was last modified: 10-22-2020 07:33 PM by RedcrowProd.)
10-22-2020 07:28 PM
Find all posts by this user Quote this message in a reply
Dwight Offline
Member

Post: #3
RE: Environment - Setting through code
(10-22-2020 07:28 PM)RedcrowProd Wrote:  I was confused a while ago about the same topic, the environment is just a holder of variables, you need to either call set() so those variables are pushed to the right settings in the engine, or push it yourself manually

set / get
void set (); // apply these settings to graphics (this will call 'set' on all members of this class)

Or like i said you can go to the members in that class and call specific set() ( you are calling density set() ?)

I RedCrowProd,

I do call the methods manually in an update function and end with a .set(). As with the example provided however, it doesn't update the environment settings...

"density" doesn't have a function to set it: I have to set the entire fog.

As I did it in my first few lines of code, it works as expected, but only if I do it in the Init function. If I place the code in say an update function (if I want to have a denser for in the morning for example), it doesn't change the environment. I hope this clears it up a bit?
10-22-2020 10:16 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Environment - Setting through code
If you want to set values through code then you don't need an Environment object but can set values directly to graphics options such as Fog Sky etc
Also this code is wrong
if (g_hour > 20 && g_hour < 5)
A number can never be bigger than 20 and smaller than 5 at the same time.
Try using || instead of &&
But for best results the transitions should be smooth. So a Lerp or something could be used.
10-23-2020 02:54 AM
Find all posts by this user Quote this message in a reply
Dwight Offline
Member

Post: #5
RE: Environment - Setting through code
(10-23-2020 02:54 AM)Esenthel Wrote:  If you want to set values through code then you don't need an Environment object but can set values directly to graphics options such as Fog Sky etc
Also this code is wrong
if (g_hour > 20 && g_hour < 5)
A number can never be bigger than 20 and smaller than 5 at the same time.
Try using || instead of &&
But for best results the transitions should be smooth. So a Lerp or something could be used.

Hi Esenthel,

Darn typo, my code actually has ||. Thanks for catching that one on here, I didn't even notice it!

I will go ahead and set the value directly and see if that works! Thanks, yet again, for your support!
10-23-2020 11:04 AM
Find all posts by this user Quote this message in a reply
Post Reply