How to create a BP Light/Lamp that turns on/off automatically at day/night cycle

Hello everyone!

I already have in my project a great day/night cycle thanx to Kleiner Baer and his fantastic tutorial

Here is the problem: I want to create a BP Lamp with a light in the component tab, and this lamp must turns on when sunset comes up and turns off at dawn.

Why i want this into a BP? because it’s more easy to me to drag the BP to the environment every time i need it. Better than creating for every light the code.

What nodes or code i need to do to get this working?

Thank you so much to all the community to help me.

Regards

You could try setting a bool in your day/night cycle like ‘IsNight’ and check that on your lamp. If it’s not night, the lamp is off. Otherwise it’s on.

If you check the sample content there’s a level called BlueprintOffice that shows how to use Event Notifiers. You could set one of those up so that night and day send events that all your lights could catch. I honestly don’t remember how that is set up, but take a look at how the automated camera interacts with the alarm system. You might be able to do something like that with your lamp and day/night.

Hello,
if you can have the time of the day from your cycle, use it as condition in a branch to light on / light off. (Or any other information you can have from this blueprint related to the cycle.)

Hi guys! Thanx for your help!

Look this is what i have in my BP:

The big question is now what i have to put in the branch to be the light turned on and off?

The values in “InRange(Float)” are the pitch position of the sun.

Thx for all!

“get” your lamp and “set” visibility / hidden in game.

Hi Gooner! I was investigating the BlueprintOffice that shows how to use Event Notifiers, but i can’t really make it work. If you can share a screenshot with your idea, it will help so much thank you!

Hi Fen! This is what i did with your help:

My problem now is that my lamp is always turned off in the scene. I don’t know how to connect this nodes.

I’m very bad in programming sorry.

Thank you guys for your time!

A pic which would work :

where daylight and nightlight are = to the value when you want light of or on.

Thx Fen for the help, but is not working for me. In my BP i need a target attached to “set hidden game” i attached the Lamp light. But still doesn’t work. Meanwhile the two functions “Daylight” and NightLight" do nothing because of the day/night system i recreate from “Kleiner Baer” tutorial. I still need to activate/deactivate the light based on the pitch of the sun(direcionallight) pitch.

It’s very hard to me to understand all of this in depth. Maybe we can share desktop streaming via Skype or something to find out a solution. I guess the community will appreciate it to get a solution to add this to their projects.

Thx you again for your time and effort!

This is my bad : I forgot to say to link your lamp to the set hidden.
And maybe float is the trouble or pitch (i used that once and it didn’t work with the pitch but worked with a make transform from it… So you can use a “round” from your pitch value to modify it to integer and change the two variables in integer. It would detect the value better. and if it doesn’t work use a print string on event tick to read the value of pitch. you maybe on the wrong output (i don’t know this day night system and not sure how it turn around.)

Hi Alberto.

If you want to switch your lamp on sunset, unhidding it in game is not the solution, because the light will hide or unhide keeping its state, on or off. You may set the brightness of the light component of the lamp from zero to a higher value instead.

There is a lamp blueprint included in UE4 called “Blueprint_WallSconce” that shows very clearly how to use a variable to set the brightness of a lamp composed of a SM and a PointLight, that you can adapt to your case. (Check its Construction Script to see how this variable is used)

Thx Luis! I’m searching for the BP but is not included in the base game contet right? And in the example content neither, where did you get it?

P.D. Hablas español?

Do you have a Variable somewhere wich tells you the ingame time? if so its pretty easy and i can make you a quick sketch

I already found the BP is in the base game content sorry my bad, Luis.

Hi , the day/night system i’m using from “Kleiner Baer” don’t use this variable. In fact uses a very advanced math expresions to determinate the rotation of the sun/lightsource, day counts and years count; even equator position to determinate the direction of the rotation sun. Is like a recreation of the rotation of the solar system. With this system you can even determinate the seasons.

I hope that you get it done. Tell us about your final result.

P.D. Sí, hablo español.

Ill work our a solution for you but you have to close the gap from daytime to your skybox. Wich means use those magical math formulars and get a daytime 0-24 and you should be set with the stuff ill upload soon

Edit: Please be patient… ill use such stuff to teach stuff to myself :slight_smile:

Edit: Just making assets… i guess my machine is going to explode soon :S

Edit: Pure Scene Set. Implementing your Day/Night Cycle Now

Yay done :slight_smile: I didnt use the Day/Night Cycle you used but that doesnt matter in the end. I didnt like the one you used because i couldnt get rid of the “Bright Night”, maybe i just didnt copy the BP corectly from the YouTube Video. However here is a example of how to turn a light on at night and turn it of at day.

Stuff i used:

IMPORTANT! Un7Zip the DemoProject Folder to your UE4 Projects Folder AND copy over a StarterContent Texture Folder into DemoProject\Content
I removed those for the sake of filesize (like 60mb)-

Howerver here is the link: (88mb)

If you got questions just ask here :smiley:

Hey ! Thx for sharing your project! It works pretty well, i really like the glow bouncing too. But i still have the same problem with mine. I want to make it work based on the rotation of the sun… And i can’t figure it out what i have to connect. Maybe you can set it in your project to have an example. That would be awesome! And i could make an screenshot of the nodes and a tutorial in the near future of it.

For example i saw that you connect the variable “currentminute” (from you BP_SkyDome) and set the time value to turn on/off the light. That works because you calculate when the sun goes down and when rise up is that correct?. But if you change the day duration in minutes you must update manually the values of time in the BP_Lamp aswell. If you make it based on the rotation of the sun it automatically updates. I quess that this would be much accurate and easy to setup the day duration.

Anyway you are very kind for helping that way. I’ll continue investigating this issue to make it work.

Bye!

when i remember corectly you have a variable in the enhanced skydome you are using wich tells you the “time of the day” the one that counts up to the DAY variable have you tried using that one?

you could export the sunrise and sundown variables from the skydome so the lamps can access it as well, that way you wont have to edit the variables by yourself.

And another idea for you to investigate would be to do the following.

Calculate the radius of pos 0,0,0 to the actual sunposition using simple math

fd875d66039fb284e31384dfef897bf17f19e93f.jpeg
sin(a) = A / C

Pos 1 (0,0,0) this is at a
Pos 2 (x,x,x) this is at b (upper right corner :wink:

A is simply the current vector of the sun * (0,0,1)
C is the VectorLength of Pos2-Pos1

now simply you want a you do asin(A / C)

and you get a acurate angle wich you can use to calculate

90°-0° day

Solution

SOLUTION

Hello everyone! First of all i must say thanks to all the people involved to contribute to get the solution. Specially to Luis Hernandez, he gives me a clever solution that leads me to the end.

First step:

I have created a BP with a light in the component tab. Then in the construcion script i’ve added this:

In the Event graph i’ve put nothing.

Second step:

I’ve opened the level blueprint and set this:

Now it works great! I can change the duration of the day in seconds and the light turns on/off always based on the sun rotation.

Again thanks you all for the help and the support!

Have a nice day!

What is this ? You know a tutorial?