Search Unity

What are the limitations of DrawMeshInstanced() with dynamics gameobjects ?

Discussion in 'General Graphics' started by anthonov, Jun 27, 2022.

  1. anthonov

    anthonov

    Joined:
    Sep 24, 2015
    Posts:
    160
    I'm trying to make a scene where there are a lot of moving objects.
    They have a rigidbody component and share all the same mesh to render.
    I noticed the framerate is limited by the rendering of the meshes. one batch per mesh.
    So I tried to reduce batches by using Graphics.DrawMeshInstanced(), but the result are not so great.
    The issue is I have to feed this function with an array of matrix4x4. One matrix per mesh instance. Iterating each update through all the objects to get transform.LocalToWorldMatrix is costly.

    Am I doing it wrong ?
    Is there a better way to instance the same mesh for a lot of dynamic objects ?