# Best way to calculate time based events?

I am creating a game that uses a lot of time based calculations. Examples are as follows:

• I am using the event tick to create a time span for the game time.
• Each Animal and plant in game is using the event tick also to create their own time spans for age and reproduction.
• Additionally for animals they also have a time span to calculate hunger and for some plants to calculate fruit production. I have included some example screenshots below for the animals.

What my game needs to do is be able to have a thriving environment of assets and in order to do that I need to be able to have potentially hundreds of plants and animals on the map. Does anyone know of a way I can achieve this without using event tick? Or at least a better way of doing this? Because I am getting severe lag on my machine now.

You will need to be a bit more specific in what are you trying to do. You can limit tick rate (Class defaults - > Actor tick → Tick interval) to 0.5 secs or more or use delay node. This will make your code executed every x time. Or do it only when your player looks at this. (Depends on how your project works).

You can use this custom node that will calculate time and date if necessary but it will do it in C++ which will be more efficient than blueprints. Might help with some of the performance issues as it reduces that calculation from running on tick.

Im trying to calculate the age, length of time until theyre hungry and length of time until the animal reproduces. It needs to line up with the game time, so ive taken the tick, multiplied it by a float and then used that and multiplied it by 240 to generate a game seconds value, thats then used to make a timespan for gametime. Same thing to calculate age and gestation etc as well.

These are all things I need to calculate and run at all times.

That looks like an absolute dream in terms of what I want Thankyou! If I hooked up a looping timer to perform regular checks at say 0.2 intervals would that massively affect game speed?

Just asking because I still need to run checks to see whether the age is maxed out so they die and stuff.

To be honest, I am not sure. Never calculated performance on the node or doing anything like that. But try it out and see if it helps. Also if you need any slight modification to the code and can’t figure it out let me know i will try and help.