UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Utility Systems / Video View System Completed

Utility Systems — UGTK

Video View System

Summary

A VideoPlayer companion that, on WebGL, downloads (or reuses a cached) remote video through a .jslib plugin and plays it back from a Blob URL; in Editor/Standalone it falls back to direct URL streaming. It exposes UnityEvents for the cache, ready, play-started and error stages.


Content


Modules Dependencies

This module has no hard UGTK dependencies. It uses Unity's UnityEngine.Video and its own bundled plugin Plugins/WebGL/Mn_WebGLVideoCache.jslib.


Setup

Drop the Video prefab into the scene — a VideoPlayer with Mn_WebGLVideoPrefetcher already attached:


How To Use

  1. Put a Unity VideoPlayer on a GameObject and add Mn_WebGLVideoPrefetcher (a Video prefab is provided). Without a VideoPlayer the component logs an error and disables itself.
  2. Set the source: either the sourceUrl field (HTTP/HTTPS) or leave it empty to use VideoPlayer.url. SetSourceUrl(string) sets it at runtime.
  3. On Start (or by calling Begin()) the cache → prepare → play cycle runs:
  4. WebGL build: calls WebGLVideoCache_DownloadOrGet(url, goName); the plugin calls back OnWebGLVideoBlobReady(blobUrl) (fires OnVideoCached), which prepares the player from the Blob; OnWebGLVideoBlobError reports failures.
  5. Editor/Standalone: sets VideoSource.Url and calls Prepare() directly.
  6. On prepareCompleted it fires OnVideoReady and auto-Play(); started fires OnPlayStarted. Any failure fires OnError(string) and logs it.
  7. On WebGL, ClearPersistentCacheForUrl() clears the persistent Cache-Storage entry for the resolved URL (use when you replace the server file). OnDestroy releases the plugin reference to the original URL.

The player is configured conservatively for WebGL: playOnAwake = false, waitForFirstFrame = true, skipOnDrop = true.

Good to know:


Testing Scene

Open VideoViewScene in the module's Debug/ folder.

What to do, in order:

  1. Play a video from a local file.
  2. Play one from a URL.
  3. Simulate the browser's failure callback from the inspector.
  4. Replace the file on the server and play again without clearing the cache.

Step 3 exists because the error path needs a URL that fails in the right way, which in practice means it never gets tested. Step 4 shows the persistent cache doing its job too well: viewers keep seeing the old video until ClearPersistentCacheForUrl is called.

The recording is the demo playing its bundled clip: press Play and the picture runs. The display in the scene is deliberately small, so what the recording shows is that frames are arriving - the only thing worth checking in the editor, since the interesting failures all belong to the browser and appear in steps 2 to 4 below.


Technical Info


© 2026 Marcello De Bonis. All rights reserved