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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Batching with dynamicly changing objects.

Discussion in 'Editor & General Support' started by Quakemaker, May 23, 2022.

  1. Quakemaker

    Quakemaker

    Joined:
    Apr 23, 2022
    Posts:
    2
    I am a student developing a game in a team and while the game we designed runs on our monster machines, we can't expect it to run for the end user. Right now at any given moment can have over 25k batches. with 0 saved by batching dropping FPS down to about 47. We are getting close to having most of the game functions complete and are now revisiting this glaringly unoptimized part of our game. After spending a couple weeks researching this between deliverables. most of the info we find is 10 years old and usually a dead end. So I am now hoping there is a solution that can be presented in a format for novices.

    What our game does:
    At scene load, we instantiate 10,000 Cells in a 3d 100x100 grid
    1.Each cell contains data that will be changing rapidly.
    2.Each Cell will has potential to be changing color rapidly::
    2a.Cell Color base has one of 3 types of terrain colors
    2b. There are 8 team colors for each player that will be blended with the terrain
    2c. Each team color blend will vary by 10 different levels based on level of ownership
    2d. One additional color for a specific event.
    3.Tilemap is generated off of a seed contributing to position on screen(after position is initially set, position should not change.)
    4. The Grid dimensions are customizable and we would theoretically like to allow a larger range of map scaling options.

    Currently, on load we instantiate the objects on the server then send that off to each client. We were advised by our instructor to try and insert the 10,000 cells into the scene as inactive objects in order to achieve batching however this causes unity to enter a 15 minutes recompiling of assemblies on every change to the scene, and potentially crashes the editor on exit if we even get that far. It would be helpful to know how to keep the above functions and still manage to optimize performance.

    We are currently using Unity 2021.3.1f1 and URP I think, Renderers are a new concept for us and I am not sure if you can mix renderers in the same project.
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Are you in need of 10.000 Gamobjects or is that just the way you render it so far?
    Using
    Graphics.DrawMeshInstanced
    to render the cells can help to cut down on per objects cost and using MaterialPropertyBlock. for the color ovveride
     
  3. Quakemaker

    Quakemaker

    Joined:
    Apr 23, 2022
    Posts:
    2
    I'm not 100% certain of my options here, which is why I tried to explain our use case. right now, some of the cells are changing color 10x a second. we frequently need to raycast to a specific cell so, not sure if combining into a single game object will prevent these things. Also, every color change is being transmitted for multiplayer replication. What I'd really like to do is get Dynamic Batching working, as I am not sure if GPU Instancing fits our use case. in either scenario I can't seem to even get these functions to work in a minimal environment.

    Example: I set up a scene that has only a camera, and a square plane for visual reference. A script that whenever I hit A it instantiates a cube prefab with a basic material. if I static the prefab and drop 20 in the scene it static batches. if I spawn 20 in the scene it does not dynamically batch. if I enable GPU instancing, still no batches. not really sure what the disconnect is with instantiated objects.

    Regarding the solution offered it sounds like it's just a graphical draw and I would be lacking the appropriate colliders
    and ability to raycast to each cell am I wrong, if so can I get a little bit more elaboration?
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Instancing is a alternative to batching.
    Batching is combining meshes on the CPU to have less draws that get send to the GPU.
    Instancing is to send a command to Draw a specific mesh on a list of position with a list of overrides to the material per object. (one command many objects of the same mesh drawn)