Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can meshes combined through Static Batching be r/w enabled?

Discussion in 'General Graphics' started by xofreshxo, Jul 3, 2021.

  1. xofreshxo

    xofreshxo

    Joined:
    Apr 12, 2017
    Posts:
    79
    I'm importing a few large buildings into my game, each with 100-200 meshes, and I would like to use Static Batching to improve performance. The issue is that I need the Combined Mesh created to be read/write enabled so that I can access mesh vertices at runtime for a decaling system. Is it possible to set the Combined Mesh that is generated from static batching to be read/write enabled? Thanks for any answers, thoughts or suggestions!
     
  2. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Not that I know: that mesh is created internally by the engine and you can't even address it.
    But you don't actually need to access the generated combined mesh: you can just use the non batched meshes for that.
    If I recall correctly, the reference to the mesh in the mesh renderer is still to the original mesh even after batching. (maybe I'm wrong though)
    You can always disable static batching and manually batch the scene only when you need to using StaticBatchingUtility.Combine()

    example:
    Save this script as "StaticBatcher.cs" and put it on the root object of the game objects you want to combine:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5.     public class StaticBatcher : MonoBehaviour
    6.     {
    7.         void Start()
    8.         {
    9.             StaticBatchingUtility.Combine(gameObject);
    10.             this.enabled = false;
    11.         }
    12.  
    13.     }
    14.