Give Page Feedback

FAQ - Can Static Batching Be Used With SAM?

SAM supports both Build Time Static Batching (BTSB) and Runtime Static Batching (RSB). There are strengths and weaknesses to both methods, however in general Runtime Static Batching integrates better with SAM. This Section covers every detail of using either method with SAM.

It should be noted that the existence of this Section is not an endorsement of Static Batching. You must evaluate whether it is the right tool for the job, and whether other techniques (like GPU Instancing or using the SRP Batcher). We cannot provide advice on this front; you must do your own research to decide which technique should be used, bearing in mind that use of one technique may exclude another technique from being used.

With that said, one great thing about SAM is that it makes testing out these tools very easy. For instance, you can easily test out BTSB, then the SRP Batcher, then switch to RSB to see which is better suited for your game!

Build Time Static Batching Vs Runtime Static Batching

For a general overview, Unity covers the pros and cons of both methods (as well as how they work) at https://docs.unity3d.com/Manual/static-batching.html

In relation to SAM, there are some additional points to keep in mind that should help you make an educated decision on which method to use:

1) Build Time Static Batching cannot be used with Floating Origin Based Worlds, as the batched meshes are locked in place. If you are planning on a creating a large World that requires a Floating Origin, you have no choice but to use Runtime Static Batching!

2) If you are using a Fixed World and want to use BTSB, keep in mind that the Origin Position must remain fixed for the lifetime of your game development, from the moment you start creating Asset Chunks for it using the World Designer Tool.

Otherwise the Asset Chunk Positions SAM tracks will not match the real position of the objects loaded in via the scenes. In the same vein, the Origin Cell used on the World and World Designer Tool must always be the same, and must never change.

3) If your Assets are stored in the Visible State (i.e., they are visible by default upon being activated), BTSB will not work correctly with Cell Visual Transition Controllers' Invisible To Visible Transitions. This is because the scene game objects need to be in an Activated state for BTSB to work, and due to this when the scenes are loaded, the game objects will be visible immediately. SAM detects this and does not perform invisible to visible transitions; however visible to invisible transitions will still work. This ultimately means when loading the scenes, the objects will appear to "pop" in, and they may end up being shown at the same time as other LODs. As such, it is recommend to disable Transition Controllers in these cases.

4) When using BTSB, you must ensure the root objects in your scenes are in an activated state. You can use the Scene Formatter tool for this purpose. You must also set the Root State setting (found on the Streamable Grid/LOD Group tab) for any LOD Groups using your static batched scenes to Activated!

5) BTSB only batches meshes in the same scene, while our Runtime Static Batching implementation is able to batch together meshes from multiple scene, so long as those scenes represent Asset Chunks from the same World Cell.

6) RSB has some CPU overhead since the batching is performed in-game, however BTSB will increase the size of your builds. You should profile both to see if the CPU overhead or larger build sizes are an issue!

7) RSB only works for meshes that have read/write enabled!

Configuring/Using Runtime Static Batching

Runtime Static Batching is very easy to setup and use in SAM. You simply need to add a Static Batcher Listener to your scene and assign it to one or more World Groupings with LOD Groups that you want to use batching with.

Please check out the link above for more information, as well as the World Grouping Listeners Chapter in general for details on how to assign the Static Batcher Listener to World Groupings.

One final note: Please remember, runtime static batching can only be used with meshes that have read/write enabled!

In addition, RSB will break if using a Per Material Transition Controller with the Use Shared Material setting disabled.

Configuring/Using Build Time Static Batching

First, remember that Static Batching must be enabled in your Player Settings to work. In addition, any game objects whose meshes you want to be batched during the build process must be marked as Batching Static.

In terms of SAM, there is nothing additional that needs to be configured, however remember that the following must be true in order to use Build Time Static Batching with SAM:

1) You must be using Scene Based Asset Chunks, as Unity only batches game objects stored in scenes.

2) The root asset chunk in each of your scenes (that you want to be batched) needs to be in an activated game object state. If you have a bunch of scenes already configured with deactivated root objects, you can use the Scene Formatter to batch activate the root objects.

3) Any LOD Groups using the scenes to be batched must have their Root State setting set to Activated (found on the Streamable Grid/LOD Group tab).

4) Your World must be Fixed, meaning it cannot use a Floating Origin.

5) You must pick an Origin Position and Origin Cell for your World and stick with it. If you already have a scene full of assets, choose values that would result in the assets being loaded at their current positions when loaded in by SAM. If you don't have any created assets, choose values that maximize the amount of game world space available to you. Put another way, try to pick values that will result in the center of your World being over point 0, 0 ,0.

It's important that these values do not change over the lifetime of your project, and also that the World Designer Tool uses the same Origin Cell that you choose. If you do not follow this guideline, the root game objects in your scene will likely be statically batched at incorrect positions, resulting in the objects not loading in at their correct positions!

In addition, please keep the following in mind when using Build Time Static Batching:

1) You can use a Cell Visual Transition Controller with the scene based asset chunks, however if your assets are configured to be immediately visible when loaded in, they will appear to pop in from your player's perspective. Performing an Invisible to Visible transition when the assets are loaded in would be a waste in such cases, and so SAM optimizes those transitions away.

Transitions from Visible to Invisible (that occur before an asset is unloaded from the scene) will still be performed as normal. In addition, if the asset chunks are being loaded in for an LOD Transition, they will end up being shown at the same time as the old LOD assets that are about to be removed. For these reasons, it is best to store your assets in the Invisible State if possible, and if not possible, forego the use of Cell Visual Transition Controllers.

2) You will not be able to use the scene assets with Cell Visual Transitioners that manipulate the position property, since the scene assets are fixed in place.

3) Because Unity requires root objects in scenes to be activated for BTSB to work, you can easily disable BTSB by utilizing the Scene Formatter to change a batch of scenes to use deactivated roots. This will be quicker than manually disabling the Batching Static flag for those scenes, though if you only want certain objects in the scenes to not be BTSB'ed, you will have to manually edit the scenes (you can use the World Designer Tool for this purpose). Remember to set the Root State to Deactivated after deactivating the scene roots!

If you use the Scene Formatter, remember to set the Root State to Deactivated after deactivating the scene roots!