- Home /
Using Occlusion Culling with remotely downloaded Asset Package
In the Unity project I'm working on, I'm downloading a fairly large (potentially multiple hundreds of megabytes) unity Asset Package from my server. Every user's project is different, so I can't bundle these Asset Packages into my app - they have to be downloaded from a server.
I'm having a lot of performance issues since there are tons of meshes in the asset package, but only a few hundred are visible at a given time. I've read the docs on Occlusion Culling, but as I understand it you have to enable it in the Unity Editor for every object which you need culled, something that won't work for me since I'm downloading these packages from a server.
I'm using an asset bundle loader script similar to this:
public class AssetBundleLoader : MonoBehaviour
{
void Start()
{
StartCoroutine(GetAssetBundle());
}
IEnumerator GetAssetBundle()
{
UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle("https:///myurl.com/myasset");
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
AssetBundleRequest request = bundle.LoadAllAssetsAsync<GameObject>();
yield return request;
GameObject loadedObject = (GameObject)request.asset;
GameObject.Instantiate<GameObject>(loadedObject, Vector3.zero, Quaternion.identity);
Debug.Log("Successfully Loaded Asset Bundle");
}
}
}
My current idea to get around this is that when I download the asset package and convert it into a GameObject, I'll walk through the tree of children GameObject and add an OcclusionArea component to them. Note that all these objects have non-transparent materials.
My question is - will this approach work? Is there a different approach I could be taking instead? Since the lack of dynamic occlusion culling here really slows down my app, I'm open to any ideas on how I could implement it, including writing my own scripts. Baking these asset packages into my app is not an option, though.