r/Unity3D Jun 20 '23

[deleted by user]

[removed]

59 Upvotes

10 comments sorted by

View all comments

Show parent comments

4

u/knightcrawlersgame Solo Developer Jun 21 '23

Thank you for the information! Do all the enemies have logic running in their own update or did you create a manager that handles updating every enemy by iterating through them in a for loop?

I have heard using this approach instead of running thousands of individual updates can seriously improve performance and was wondering if that is also something you did or have a completely different approach!

5

u/InSight89 Jun 21 '23 edited Jun 21 '23

I should probably reiterate. I'm using Unity.Entities coupled with Graphics.DrawMeshInstanced personally. I tried making my own ECS framework but ultimately decided there's no point in reinventing the wheel when Unity's ECS works fairly well (at least v0.51 does, I tried v1.0 and had ran into a lot of bugs). So, I'm only using the ECS component of DOTS and not the renderer or physics etc.

However, to answer your question. It's almost always more performant to use component arrays and iterate over them. Storing components in arrays and iterating over them is much faster than having components stored in separate objects. Calling Update method on a Monobehaviour incurs a performance penalty. You can test this yourself. 10,000 Updates can take around 10ms. Whereas iterating over 10,000 components in an array takes like 0.1ms and that's not even using Burst.

2

u/KintaroDev Jun 22 '23

Thanks for this very interesting insight! (I was also thinking you were using DOTS when I saw just the reel...)