I generate lots of identical geometry on runtime with Instantiate() (from two static prefabs atm) but the renderer does not use static batching although static batching is enabled in the renderer settings. using unity pro / deferred rendering path.
do i have to make additional steps (other then marking the prefab static) to enable batching.
the user should be able to add additional instances of the prefabs and also destroy some of them. would this even work with batching?
edit: non of the objects are animated or moved just plain static meshes with identical materials
To enable static batching on instantiated objects, you need to use the static batching utility. The way I would suggest doing it (which as worked for me) is to add the GameObject reference returned by the Instantiate function to an array and pass that array to the combine function.
This is such a huge problem, batching in Unity is way too finicky.
You’re right about objects instantiated in script posing a problem. No idea why, but I found a workaround on the forums!
gameObject.SetActive( false );
gameObject.SetActive( true );
When you create the objects in your code, set their parent to an any gameobject. Put a script on that gameobject, and in the Start() function, use the code written above. All it does is quickly turn all your objects off and then back on, but for some reason this works! It refreshes your scene, and suddenly batching behaves as intended again.
Using deferred lighting poses a bunch of new obstacles, but I just recently managed to get it working as well by setting all the objects I wanted batched to static, as well as turning off light-maps for the scene, and not using any transparent materials.
Hope this helps anyone else who’s having trouble with this!
you need to have the same material on objects that you wish to have batched and they need to not move. from the look of your scene, I am betting that you have animation. static batching only works on static things.
I have the same problem. When I add objects to the editor and run the batching works correctly, but when I use my script for instancing objects then there is no batching at all.
Any solution? Someone said that it’s related to shader, any idea?
Joel