- Home /
Populate people in city with DrawMeshInstancedIndirect?
Hi,
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:
The people move on path and can disappear when get into the house.
Each person (or group of people) can disappear when a specific event happens (for example: the house near that people is destroyed)
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.
Answer by NathanJSmith · Sep 14, 2018 at 08:16 AM
Use DrawMeshInstanced() instead of DrawMeshInstancedIndirect().
Requirements:
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.
Thanks :) the answer above is already the implemented solution. The detail implement is based on the need of the project - maybe more complex, maybe simpler. Check the forum thread for more detail and discussion.
Answer by I5 · Sep 13, 2018 at 05:23 AM
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).
I know it's hard to create, but do you think Draw$$anonymous$$eshInstancedIndirect is capable to meet the requirement in the question. Is it because Draw$$anonymous$$eshInstancedIndirect isn't flexible enough to set position for each mesh draw?
Your requirements state:
"The people move on path and can disappear when get into the house."
If by "move" you mean realistic-like human movement, with any sort of rendering of body limbs, then no, I don't think Draw$$anonymous$$eshInstanceIndirect will meet your requirements, at least not until you first create animators, set up animation, navigation, colliders, and on an on (all the "dials").
$$anonymous$$y understanding of Draw$$anonymous$$eshInstanceIndirect is that it is a lower level/layer of code that Unity provides to coders/developers to help them improve the performance of their code/game, and make it easier to render a large number of objects (that have already been setup). There is a lot of stuff you have to first do, setup, code etc ahead of time before you can take advantage of Draw$$anonymous$$eshInstanceIndirect. If you did all of that work, then yes, Draw$$anonymous$$eshInstanceIndirect could be something you can leverage in your code that would help you and save time and avoid performance problems. Essentially, you have to do a lot of work setting up your characters before you can realize the benefits of Draw$$anonymous$$eshInstanceIndirect.