Download

Sun and Sky, how to make it track current "now"?

I’d like my sun and sky system to be continuously updated with the current time. I’m guessing I have to put some kind of timer into my level bp and poke the sun sky system’s current month/day and solar time. I’m not sure how to do that however. Can anyone give me a clue? If that’s possible, I’d also like my scene lights to turn on once it gets kind-of dark. I wonder if that’s asking too much :p.

Thanks.

If you just need realtime updates, that’s super easy. Plug these nodes into the GetSunPosition node inside the UpdateSun function. That will get your PC’s current time/date. Next, bypass the hash value in the event tick, and enable realtime capture on the skylight.

Thank you. I think I did it correctly… my lighting seems to be kind-of morningish (it’s 09:44 here)…

Alright, had it running today and verified that it’s not updating it in real-time. Sat next to a shadow for an hour and it didn’t move. Do I need to invoke the update on a timer somehow?

Who calls update sun? How often?

An excellent question. Nobody. Where should it get called and how? I’m assuming the level bp? Edit, ah I get it. In the event graph I see it won’t get pinged if it’s not moveable. So I’ll make it moveable.

Another edit, no the components inside the system are already moveable… should be getting called on each tick. Apparently it isn’t.

Depends. Any on tick timer will do if you have the overhead for it. As far as how often, that too is something you should decide based on the project’s constraints.

regardless. Even if your code is correct, unless you call that update function nothing will actually update.

So ideally I think I’d check it every minute or so but I don’t know how to setup a timer to do that. I assume (I’m a developer, new to blueprints though) I have to somehow reference the sunsky object in the level bp and add a timer object to ping it every now and then… I looked into this yesterday and UE example is kind-of weird and convoluted… It isn’t clear how I transpose that onto my requirements.

Set timer by event

https://docs.unrealengine.com/en-US/…ent/index.html

Pack all your logic into a function. Initialize the logic by calling the function, then pipe in set timer by event. The custom event executes the function.

A timer is one thing. Running something periodically another.
How you do it depends on the load that the function puts on the system you are building for. Since I have no idea what you are doing, I can’t even attempt to give you a solution.

As a general rule of thumb.
Take OnTick, plug the delta into a custom variable. that’s the game time ellapsed for the object.
from then you can check the variable being above a certain threshold, run the function and reset the counter.

Using a timeline may be cleaner.
Add a timeline, set it up. run it once at Begin Play. Hook finished to Play From Start - after calling the function. That way you have 0 overhead from Tick event setting the variable/the engine just sets another billion variables instead :stuck_out_tongue:

I added something that I think looks vaguely correct to my level BP. What I’m trying to do is make my sun-sky system update to be now(), so right now the scene should be dark and tomorrow morning it’ll be light.

Anyway I opened my level BP and added something to that. It already contained some blocks for starting a media asset and I’m not sure but think I’m correctly setting up a timer to call Update Sun on my Sun Sky object. I’ll be better able to test it tomorrow I guess. I expect to see shadows and sun position changing over time. Does the BP look correct to you?

Your current setup will have a 60 second delay before the first update will happen. So, Add an instance of “Update Sun” just before the timer. Leave everything else the same.

That was my first image, bypassing the hash check in the event graph to call it every tick :slight_smile: setting a timer up is a much better way of doing it on a performance basis though.