I’m new to Unreal, learning a lot atm. I would love to to learn and read more about the following topic. Can someone point me in the right direction?
How can I trigger events base on the system time and date with blueprints? An example would be the game animal crossing, where things change and happen based
on the system time. Even better would it be if it works in multiplayer (the server time and date?).
Thank you for the reply. But it’s more that I want to have an event trigger on a specific date and time. For example I would like to have an actor spawn on 12 june 7:30 pm system time (or server time). Or have an actor spawned every day at 7:00 pm.
With this node you can get the information you want. For it to work properly, for you, you should compare the nodes: Day, Month, Hour and Minute for the one you want. I’d recommend you to make the following:
If (Day = 12 && !bEventCalled)
{
if (Month = 6)
{
if (Hour = 19) //7pm
{
if (Minute >= 30)
{
//Call Event
}
}
}
}
Leave the minutes comparison for last and add the greater than comparison (for the case all of the past comparisons matched and due to a lag or something the event was not triggered the current minute), cause this is the one that has the greatest variety frequency between these variables.
You can create a function to that to be called every 60 seconds, if you want, using Set Timer by Function Name.
Haha, it’s ok, my fault I couldn’t find an easiest way in my mind to bring the idea to you.
Basically each If is a Branch inside blueprint. So, if it’s true, you follow what’s inside the brackets. The bEventCalled is a boolean variable that you will set to true when the event was called first, for not calling it twice. The ‘!’ before means “Not”. So, if bEventCalled is not true, then…
You can read by: If Day = 12 AND bEventCalled = False, then: If Month = 6, then: Hour = 19 (I presume they measure in 24h range), then: if Minute is equal or greater than 30, then: Finally, execute the desired event.
It’s a chain of comparisons. The sequence you will be comparing matters because you can avoid using it too frequently, ex.: The first comparison only will trigger the others if the day is equal to 12. You will have 12 occurrences of this comparison during the year. If Month was the first to be compared, during all the duration of the month (30 days), you will be triggering this comparison. In terms of isolated events, this will not be that much expensive, but if you have lots of dated events, you should start considering this optimization.
Yes, I fully understand now what you are saying. Thank you, this helped.
Would your examples also work on a server system time for multiplayer? Or how would I approach this?
I also read that using lots of events with the event tick could have a huge impact on the performance of the game. Is this true?
For example if I have lots of events happening on different dates and times.
I believe this is the best approach, in terms of logic. The question is which is the best class to use it…
I don`t know the best practices for dealing with specific dedicated server only events, but I believe all of this should be handled inside the GameState Class. You would need to do some research or ask someone else to confirm my information.
Yes… You should take care on this. You can use, too, the Set Timer by Function Name node for some functions you thinks it`s not necessary to call it too frequently.
The most expensive calls, afaIk and came to my mind at the moment, you should avoid using(if possible) on event tick is Get All Actors From Class, Cast to, For each loop using big arrays… whatever expensive operations, in general. Spawning can be expensive, too, depending the complexity of the actor (number of components to load, Meshes, dependencies in general).