Best way to calculate the age of something?

Im creating a nature simulation game with heavy RTS elements. I have a lot of animals and plants that the player can place in their environment and they all have a lot of things that I need to calculate (Age, Fruit production, gestation lengths etc.)

My current method is using an event bound to a looping timer. So every second (Time Unit) the event fires and adds +1 to lets say the age.

Ive then taken that Time unit and multiplied it by a float called “Game Speed” Which seemed to be working fine or so I thought. When I used a dispatcher to set the game speed variable in order to increase speed and make things move along faster. It appears to be skipping the +1 to the age in random cases… I can not for the life of me figure out what to do about it.

My best example is I have a patch of grass in game. It has a component which uses the above method only it decreases a float variable “Lifetime” by 1. Then when Lifetime reaches <=0 the grass patch dies. But it doesn’t… It carries on long past when it should.

Is there any better way of doing this? Other than to use the event tick.

Have you tried using the increment node instead perhaps? Is your time in integers? If so, increment works wonders.

Used that. Its given me a much smoother increase but its still doing the same thing :frowning:

Setting a break point would help you narrow down and figure out why that part of the script is not being triggered. Maybe it could have something to do with calculation load but I kinda doubt it.

This is a very good way to go about it. You’d have a master “clock” keeping track of ingame time and the objects and actors only need to look at it. If you wanted to simplify it further you could have “growth times” at set intervals, where a message would go out to the actors in the level and they would decide if ot was time to grow. Less constant strain and if it’s efficient enough there shouldn’t be any hiccups. Lots of games do this. Plus you can set the growth time in smaller increments so it doesn’t seem so artificial.

Probably a solid way to do it would be to have a time manager (ie, your game mode) and each actor to just log their time of creation.
This way there’s only 1 object keeping track of time, and all other just read from it.

Then you can check as frequently as needed to to see how old it is:

GameMode current time - Actor creation time = Actor age

Then all the actors have to do is to evaluate their ages to see what it is they should be doing.

As the below answers state you should have an actor keep track of the “time”. Here is a link to a tutorial that will give show you how to create a custom blueprint node that will generate a “time stamp” and also output a “date” for you to keep track of things. You can then simply compare times/dates of when things were created. Hope this helps.