I see the API DrawMeshInstancedIndirect is efficient to draw a large number of mesh.
My purpose is drawing a large number of people in the city, similar to SimCity people. It requires:
I’ve checked the DrawMeshInstancedIndirect example (github) and see that the draw mesh is moved with the shader file, not C# file. So I don’t know if it’s possible to use DrawMeshInstancedIndirect to populate the people with the requirement above?
Thanks for your time.
You’'ll need an entirely different solution, and it will require a high LOE (level of effort), to include character models, rigs, animators, navmeshagents and a lot of coding. Sorry for the disappointing answer. The amount of time and resources to create the SimCity people is likely in terms of months to years and millions of dollars. Unity only provide the “dials” to create a world, but you have to setup, code and configure every dial, and there’s hundreds of them, that you control using the editor and by writing code. I’d guess that there’s about 200,000 lines (or more) of code that creates and controls the people in SimCity (and not including the environment).
Use DrawMeshInstanced() instead of DrawMeshInstancedIndirect().
The people move on path and can disappear when get into the house. → You can pass the array of transform (which is position/rotation/size, use Matrix4x4.TRS() to set each of them) to control the peds movement.
Animation —> check zulfajuniadi for his incredible open source Animation-Texture-Baker on github. Edit: About animation, it’s just the shader play animation from an image file: check this project Animation-Texture-Baker of sugi-cho which is simpler and easier to understand.
Each person (or group of people) can disappear when a specific event happens (for example: the house near that people is destroyed) —> Unlike DrawMeshInstancedIndirect(), with DrawMeshInstanced() you can easily call multiple DrawMeshInstanced() each frame, so make each DrawMeshInstanced() a group of ped, if you want a group of ped disappear then stop calling DrawMeshInstanced() for that group of ped.
Check this forum thread.