Day / Night Cycle with state

Hello,

I have checked lots of forum and hub questions related to this question (lots of topics around there) yet couldn’t find the tip I am looking for. Anyway, I was experimenting different conditions with the blueprint system. Since I am pretty new in Unreal Engine, I have a few questions related my day / night cycle attemt. First of all, I will be trying to push my limits forward by making my scene as realistic as I can. Therefore it will use a lot of GPU, so I will try to decrease the CPU / GPU usage to prevent more hassle.

Here is my question:
I am trying to create 2 states: Day and Night. With a key input, it will switch the state. Imagine sandbox games where day/night cycles effect the whole city lights. Hopefully, I have only one flat

In day state:

  • Sun will be on top
  • Fill lights will be on
  • Night lights will be off

In night state:

  • Sun will be on bottom
  • Fill lights will be off (might be on with changed values, not sure yet)
  • Night lights will be on

I have already created the cycle with a timeline to demonstrate the flow and attached one of my light BP’s to make them on and off. It is working flawless, yet considering I have other light sources needs to be BP and codes within them, it sounds like I am computing unnecessary things.

I have something in my mind to simplify that logic above, but not sure if it will work. Is there a way to create such states within a variable so I can simply get Sun position to determine if different light bp’s are all on or off? I have doodled the states into nodes with pen, and logically it makes sense yet I have no idea how to achieve those with real unreal nodes.

I imagined Day and Night states predefined seperately in BP’s and cast to Level BP where the sun state calculated to set a state into 1 and the other 0 (or switch, haven’t used it tough) If this makes sense, am I supposed to get all scene lights into those state BP’s to set all values 1 or 0? If so, how is it possible to cast 1 from Level BP to those states to activate different light sources?

Sorry if I made it more confusing with my ideas :slight_smile:
Thanks so much for your help!

Okay, just before I post this question someone posted an answer to a different post that covers most of my questions with using tags to switch different lights. I will try to implement the logic into my blueprint which uses sun rotation to activate those lights instead of using trigger based key input. I promise if I can manage to find a solution, I will post the blueprint here!

The other post helped me to get started with a different logic is here:

Finally I managed to solve the Day/Night Cycle BP! Now it is working flawless. As I promised above, here is the BP I used. I am sure there are better ways to make it more performance efficient, yet that’s all I could do for now. Hope this helps!

To sum it up
First of all, I tagged every light as night or day in order to group them in blueprint to prevent toggling them one by one.

On Event Begin Play;

  1. I repositioned the sun location (couldn’t do it on editor)

  2. Get all Light classes and picked only Light_Day tags I did before and added them to Light Group Day

  3. Get all Light classes and picked only Light_Night tags I did before and added them to Light Group Night

On Key Input

  1. I used branch to decide if the sun is on top or not
  2. If true, timeline animation makes it night by going through 270 to 90 and after 1.5 secs delay (before it gets dark completely) visibility of lights in those groups are changed.
  3. I false, timeline animation makes it day by going through 90 to 270 and after 1.5 secs delay (before it gets light completely) visibility of lights in those groups are changed.

Here is the Level BP I made

HI! can you please upload the image bigger? it’s hard to see :slight_smile:

nice work!

HI! can you please upload the image bigger? it’s hard to see :slight_smile:

nice work!