Which solution uses less resources?

Hi, I’m creating a game where the world has nodes of resources such as plants, mushrooms, minerals, which grow overtime and go through several growing stages.

I thought about two solutions and I’d like to know which one is less resources consuming pls.

1- I use a single timer, every x seconds the script checks all the nodes; if a node is active (a node is active as long as the player is nearby), it starts a function which updates the stage of the node. My main concern about this solution is that the script will have to check several hundreds GameObjects every time the timer hits the magic number (maybe once every 5 mins or so).
The nodes would be children of a GameObject and I would use a foreach loop. Maybe I could easy the loop by changing the parent of the node when it becomes active, therefore I could loop through a shorter list of GameObjects.

2- Everynode has a timer and it works only when the node is active (as long as the player is nearby). This solution avoids to check all the nodes, though if the player is in a really populated area (a forest for example), there will be dozens of scripts and timers active (lets say max 50-70 nodes).
I think this solution is better because everynode will have its own timer, although I don’t know how heavy could be to have up to 50-70 active scripts/timers at the same time.

What do you guys think? Thanks :slight_smile:

Well, unless growing script is really heavy or your game will be for slow phones, 50-70 nodes is close to nothing.

Thank you. I thought it could be a problem to have so many timers because they’re in the Update function and I’ve read it’s better to avoid putting things there. I guess the 2nd solution will do then, thanks again :slight_smile:

Mind if I ask another question, it’s related to this system and performances.
I use a child with a collider set as trigger on the player to activate nodes and the floor of the world is made of tiles, thus the trigger keeps triggering the tiles. Is this continuous check of the tiles bad for performances?

I kind of avoid that with a simple check on the tag of the object the trigger collide with; I was wondering if this is the best solution or maybe there’s a way to avoid all these check trough the use of layers.

Thanks :slight_smile:

Well, it actually depends on how much action you are doing in your game, if you have unity pro, then you can look at profiler, and if not, then at least you can look at stats(button near button “maximize on pay”) and check for numbers. There is no big need to write super optimized code if your game runs fine right now.