Home

Awesome

Unity-WebGL-Utilities

Some helpful utilities for Unity WebGL games based on and inspired by the Unity team's blog posts and WebGL essentials asset packages.

Installing

Grab the latest release and import the unitypackage into your project.

WebGLMemoryStats

This is a simple behavior that you can add to a persistent game object. It will periodically log WebGL memory statistics to the browser console to help you tune your WebGL memory size:

Updated CachedXMLHttpRequest

The original version of CachedXMLHttpRequest unfortunately has a few bugs. This package includes an updated drop-in replacement that resolves the following issues:

The updated version also adds some functionality to give you finer control over the XHR cache:

For example, the following configuration will never cache files containing .xml, .php, or xhr_nocache, and requests with .unity3d in them will not be re-validated when being loaded:

var Module = {
  TOTAL_MEMORY: 268435456,
  CachedXMLHttpRequestCacheBlacklist: [/\.xml/, /\.php/, 'xhr_nocache'],
  CachedXMLHttpRequestRevalidateBlacklist: [/\.unity3d/]
};

CachedXHRExtensions

This package also provides extensions to the CachedXMLHttpRequest addon which allow you to clear and query for the existence of items in the cache. This can be useful if you pre-fetch your asset bundles on startup to avoid doing so multiple times. The classes used below are in the Kongregate namespace.

Clear the cache:

CachedXHRExtensions.CleanCache();

Query the cache:

IEnumerator CheckIfAssetExists() {
  var query = new CacheEntryQuery("https://whatever.io/file.xml");
  yield return query;
  if (query.IsCached) {
    Debug.Log("Asset exists in cache!");
  }
}