Static or dynamic batching is not appropriate for objects repositioned occasionally. (in few seconds or maybe few minutes)
For this, can I do batching manually in script?
Static or dynamic batching is not appropriate for objects repositioned occasionally. (in few seconds or maybe few minutes)
For this, can I do batching manually in script?
Unity provides a couple of options that give you more control.
StaticBatchingUtility.Combine:
Mesh.CombineMeshes:
You can write your own batching code using the Mesh class.
–Eric
Eric5h5, I am interested in doing this. What parts of the mesh class should I be paying attention too?
anyone who can point me in the right direction?
All of it, aside from boneWeights and bindposes (assuming you’re not doing skinned meshes). Learn how meshes work and it’s fairly straightforward.
–Eric
Well, I was going to do a custom system for static things, and unitys system for the dynamic enemies, but it is too limited. I assume this is a internal limit though?
I want to make a custom batcher because I have a large map, that is sort of randomly jumbled around when it loads, for variety. Trying to learn how/when to use whats in the documentation.
Is there a script for Unity’s version of batching? Just to learn how things work together.
cant i just get the position and rotation of the mesh, once it is in position, and then make that the the position and rotation of the mesh in Graphics.DrawMesh? then just assign the rest of its paramenters? But first maybe I should tag all the prefab mesh parts, and then get a list of all those in an array, then get position, rotation for each, and… idk.
Not really sure how this would batch all the different meshes as one though. I feel like im missing a lot.
Would this even work with LOD? since sometimes, I wouldnt want the high to be rendered, and replace with low poly? The LOD would be set up as one big mesh for low, and lots of meshes for the hi poly.
I suppose I could base a custom LOD around it where, if player is far enough away, stop drawing hipoly mesh, and batch out the low. I could do this by putting an if statement before the GameObject.DrawMesh. And I could have all the low poly tagged as something else, and return an array of them as well, and draw when needed.
Unitys batching does not run on scripting, its part of the engine.
Replicating it would also not be very performant as static batching in Unity is pretty data intense (build sizes can explode if you use it as it stores a lot more data than without static batching) which would trigger the garbage collector.
What you could and likely will want to do instead is import the ‘Scripts’ Asset Package which comes with the Unity install and then check out the ‘combine children’ and its related mesh combiner script which can be used to create various forms of static batching pretty easily at the cost of a slightly longer level load time (it combines it on startup, not at edit time).
Ive looked at that, the only problem is you can no longer use culling. Of course sense this must also be baked into editor, I would have to create my own of it as well. But im not really worried about culling system, I have a few methods in mind.
With the popularity of random/procedural generation and things lately, I would think Unity would be considering working something into the built in system. No idea what they could do though…
Since can’t really bake from the system, maybe bake from the cloud on startup? Idk.
I would have over 6,000 scenes with the minimum amount of randomness I want to implement. So I cannot make these each their own scene, because Unity can’t handle even 80ish from what I read, and it would just be excruciatingly awful to do all of those by hand.
If anyone knows a good learning source to build myself up to creating a batching system, that would be helpful to me. whether it is about batching or mesh class itself.
If you use a skinned mesh renderer, the performance is rather competitive with unity’s own dynamic batching, so you might want to try that (with vertex bone influence count set to 1)
This would allow me to batch? If im going to write my own batcher, I might as well make it a static system, that calculates after the level is loaded up(the randomness of the level is placed).
I am assuming the batching goes by world space and not local? Otherwise, I could just make the batched parts children of a empty game object, and move that around. But im 99.9% sure, it goes by world space…
do you still get a draw call for the non-currently displayed LOD? and can LOD and batching be used together? Like say, bunch of staticly batched objects grouped into one of the Level of Details?
What if I loaded map chunks as scenes? Bake each scene with occlusion, batching, lighting. Could I then have those pieces(scenes) moved around in the new scene and have the systems work? Or would unity not realize what is going on and have a heart attack? What do you guys think