Closed jpw1991 closed 1 year ago
Well, the large list is always empty when it begins, and only ever filled once.
FindClosest
for other parts of the AI, such as LookForCuttableObjects
, speeds it up?Well, the large list is always empty when it begins, and only ever filled once.
Whoopsie. Yeah, I had imagined a line there. I promise that is unintentional...
I'm gonna profile the performance of the neckros and woodcutters and report back.
Okay, Neckros are 31% more efficient than the woodcutters due to the new neither is inefficient in the first place. Low FPS can't be from their searching AI because they don't search every frame.UndeadMinion.FindClosest
, which I find surprising because I don't think it's optimized. Second surprise:
Oh, wait, the neckro might be faster just because of the mask used for OverlapSphere
.
The only way to make it faster is to start with smaller radii and increase the size as you said. Also, it might help to try OverlapSphereNonAlloc
:
https://docs.unity3d.com/ScriptReference/Physics.OverlapSphereNonAlloc.html
BUT this might be a case of premature optimization; is there ANY Humanoid you can have a hundred of that wouldn't slow the game down? So much time each frame is spent updating the walking animation on the main thread.
If I made a mod that put the animation updates on another thread, you could probably have hundreds of creatures while still being playable.
Oh, there's a different problem with the woodcutters that I didn't find until I did the profiling again: The woodcutters were checking for something to cut every frame: nextCheck
is never set to the current time in Awake.
So if you've been running the game for a few hours, woodcutters are going to LookForCuttableObjects
every frame for Time.time
/UpdateDelay
frames. After 3 hours of playing, that's 1800 frames, or 1.5 minutes at 20 FPS.
I don't know if it should close this issue, but this will definitely help.
Oh, it might. Because 1.5 minutes at 20 FPS is another 1800 frames, so it's not catching up. So it could be a permanent performance loss until... all the games are restarted? Maybe even the server? Yeah. This was a bigger issue than I thought.
With this fixed and the default time of 6 seconds between searches, the profiler looks like this (with 50 woodcutters and 50 neckros each with search radii of 1000): That's not bad, considering that is way too high of a search radius.
Great finds. Thank you
Description
Worker minions pretty regularly scan for stuff to cut/mine. But really they needn't scan very often at all: Trees and rocks don't move.
Is the feature related to a problem?
Yes. Having a lot of miners/lumberjacks can cause framerate drops.
Solutions
Large Scan + Small Scan
I think there should be an infrequent large scan accompanied by more regular smaller scans.
Large scan:
Small scan
Small scans are more frequently done and used to find stuff like logs or rock fragments that have formed as the result of harvesting, but these are always nearby and so the scan can be restricted to just a few meters and only performed after the current target is harvested (eg. tree breaks into logs, perform another small scan, target logs).
Workfllow