NPCs who know the time

Good morning :smiley:
So, I want to program a time-of-day-system in a game, where the NPCs should react to the time. As in, do some specific activities at a specific time. I made a blueprint, that updates the time of day and adjusts the sun position, when I drop it in the level.
My Question is: What is the best way to tell the NPCs the time?
Currently, my plan is to implement a blueprint interface, that sends hour and minutes to every Blueprint of the NPC class. But, because I don’t exactly know how many NPCs there will be, I’m afraid that this could be very detrimental to the overall performance of the game.
Is there a more elegant way to send the time to all NPCs?

Thank you :smiley:

edit: Not exact code but pseudo code structure:

Probably better to have a central planner with a single tick / timer by event function.

Have a map with times as keys and activities as an array. Have NPC’s subscribe to the cental planner via an event dispatcher from the activity.

Then on update of the central planner check if an activity is set for the current time (does map contain key of current time) => if so then fetch it from the map => from the value get the activity => call it’s event dispatcher => everyone subscribed / bound to the event will do their own internal logic

3 Likes