Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

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

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

  1. anthonalone

    anthonalone

    Joined:
    Sep 24, 2015
    Posts:
    146
    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 ?