Closed asineth0 closed 1 month ago
It's a fair point that this is poorly implemented. For the next update I'll remove it from the dedicated server build as you suggested. Ideally, I'd like to implement some sort of timer queue in the future for things like plants finishing growing, resetting objects, respawning, etc.
If I'm not mistaken, Transform.Find ought to be somewhat slow. Might be worth keeping the foliage transforms as nullable fields.
Thanks Jdance, you're right that Transform.Find
can be slow - in fact there was an issue relatively recently with a plugin UI that had thousands of children - but in this case it's only finding those two direct children on the frame the plant state changes so it shouldn't have a particularly noticeable impact. If it were using Find every frame or there were more to search through (deep hierarchy) then it would almost certainly make sense to save a reference to them.
Ah I see. Makes sense. 👍
I see in
InteractableFarm.Update()
it seems to check whether the plant is grown and swap out the game objects.The unfortunate problem with this is that it requires calling Update() very often and while this function is empty on the server, it still wastes a lot of CPU. For example, with 8000 crops, disabling the InteractableFarm component on the server can cut the CPU usage nearly in half.
Moving all of this into something like
InteractableManager
would be a relatively simple fix for this and would improve performance on servers with lots of plants in-game (eg. RP servers for example). Or alternatively, just making sure theUpdate()
function doesn't exist on the server so Unity doesn't waste CPU calling it.