Playing background music based on time of day

Hi everyone, I have been trying to implement a background music system in which changes the type of music based on the time of day (day and night versions of the music). Here’s a sample of what I have done however, it doesn’t seem to work and keeps giving me a "Blueprint Runtime Error: “Accessed None trying to read property Good_Sky”. Blueprint: Primordium Function: Execute Ubergraph Primordium Graph: EventGraph Node: Branch" error. It would be helpful to get some feedback on this thanks!

You haven’t assigned the GoodSky variable.

Thanks, however even after fixing that part I still am not able to make the music switch properly based on the day and night cycle. I have also attempted to use the directional light rotation as a method for a day and night cycle but it still does not operate as I want it to. Here’s the modified version of the script.

This really helps but I don’t know if I’m doing this wrong. I have used an audio component and a soundwave for sound library and playing sound. Maybe it is the condition that is not working correctly? When the day turns into night, the sound does not shift to the night version of the theme. Hopefully this image may help?

Hi - you’re passing the same variable for both day and night :slight_smile:

Ah! Thank you it works now! You helped out a lot dude!

Ah, now that’s a different question really, eh?.. :slight_smile:

In fact, someone asked this very thing the other day, there’s a bit more to it than meets the eye. You need this kind of code:

Tell me if you get stuck.

1 Like

A perfect and free music selection.

A perfect and free music selection.
Visit the website to download a list of free phone ringtones.

How could I do this with the ultra dynamic sky from the marketplace? And could you explain the example you gave?

Exactly the same :slight_smile:

image

Thank you for your reply, was also wondering how to get variable sound within the Play sound custom event. Also I’m doing this in my level blueprint.

Well, same way as above :wink:

Sorry i’m stuck on that Play Sound event node having the sound variable. I don’t know how to add that.

I’m having problems with the playing sound variable connecting to the sound variable before the != node. What am i doing wrong?

Ok, let’s try again :slight_smile:

In UE5, anyway, you need these types

image

Then you should be ok.



It seems that my sounds are not changing because i only hear the daytime sound. And yes i am using ue4.26. I think I may be doing something wrong with the audio. Maybe these pictures will help.

For now, just do it with a flipflop node, so when you call the event, it always swaps the sound?

Where would i place the flip flop node to make this work?