maanantai 13. maaliskuuta 2023

Unity video playback on canvas

I toyed a bit with video playback on unity last  week, these are the findings, "how to play video on unity".

Setup

Put a video clip into Assets folder.

 

 Setup the video in inspector, transcode, resize etc. whatever you need.

Create a RenderTexture in Assets

 

Setup the render texture in inspector, I think size should match the video resolution.

GameObject

Create game object with Video Player component, that has VideoClip source set to video clip, Render Mode "Render Texture", and Target Texture set to Render Texture we created on the setup phase.

Create game object under Canvas object, add Raw Image component and set the Render Texture we created on setup phase, as the Texture.

 

Problems

at first I couldn't find any tutorials for Canvas video playback (I suck at internet search).

The tutorials I first found were doing Renderer override rendering, which was not my goal.

The first solution I had, had RenderTexture and a dedicated Material for UI which had render texture attached as color texture. Works, but this Raw Image approach is even simpler.

Links