How Would I Optimize My Entity System In CPU

i already fixed it yes lmao bc of spline

2 Likes

Thatā€™s done for all created mobs so move it to the start of the code and make it edit all mobsā€™ collision groups at once.

Small miss spell here, lol.

2 Likes

hello thank you for replying and i did your method where i put the Collisiongroup at the start but it didnā€™t change anything And Yes The Dictionary was spelled wrong Sorry About That I Am Not That Great in English. EDIT:
here is 1k mobs

3 Likes

Quite weirdā€¦ also add a wait to the spawn loop:

if i % n == 0 then task.wait() end

Change n to a reasonable number, maybe 200 or 500, test and see which performs the best and lets the system run at high speeds.

I was just informing you in case you didnā€™t mean it


isnā€™t it same if i spawn it at once bc its the same amount of mobs?

Yes but adding a wait decreases amount of iterations ran without a ā€œbreakā€, putting too many waits causes the best performance but worst speed and vice versa, thatā€™s why you need to find that perfect n for you.

if its the same wonā€™t the CPU Be Same And I Would Have The Same Lag?

No, try running a loop 1 million times and do smth thatā€™s resource intensive, then do it and add a loop each 100 iterations, u will notice the difference.

seems to be same for me man idk. but ye i still need help

What catrom model are you using, i wanna check its performance

the catrom spline is this one : https://github.com/ecurtiss/CatRom/blob/master/README.md

You might check out this response I made to a similar post. TD game entity system, help on optimization - #28 by CompilerError

With the optimizations I mentioned in the post I was able to handle up to 18k entities at 60FPS. I didnā€™t mention in the post, but when I was testing I was able to control those 18k entities while also knowing which ones were within tower range in real time, in my tests I had 79 towers.

If the entities did not have character models then I was able to run about 150,000 while maintaining 60 FPS.

In my example, my units are clumped together, which actually makes the tower problem notably more performance heavy than if they were spread out.

Minus the tower implementation, all of the other optimization tricks I used were noted in my two posts on that topic.

wait are you the owner of vault td game which has an optimized entity system?

Nah sorry, I am not. His methods are interesting and good but not the best.

Also, the catrom module movement system might backfire, Since you do not know where the enemies are/which node they are. These can affect towers with the ā€˜Firstā€™ and ā€˜Lastā€™ targeting. If you think you can calculate the distance of each node, well consider a waypoint X the enemy is going to. But waypoint Y is more near.

then what do i use i want smooth curves

Splines are just a set of straight lines, the ā€œcurvednessā€ of which is based on how high the resolution of the spline is. Use whatever spline gives you the best looking result, treat each point on the spline as a waypoint and interpolate the position of the entity between them. Given a waypoint index and a time at which the entity reached the previous waypoint and a time to the next waypoint you can determine an alpha value for a lerp and smoothly move along the ā€œcurveā€.

Why not listen to this guy? He has maybe the best systems

wdym i have already read his post or reply.

soo you are saying when i want to make a turn i should use spline and when i donā€™t want a curve i will use lerp?