3

I'm confused as to what is going wrong here but I am sure that the problem is my rendertextures/video players - I have maybe 20 gameobjects that are iPhones, and I need animated .mov files that I made to play behind the screens.

To do this I followed tutorials to hook up Videoplayers with render textures (now there are about 8 of them) like this, then plugging the render texture into the emission slot in a material:

enter image description here enter image description here

And with even 2 render textured cubes the game is INCREDIBLY laggy, here are stats

enter image description here

I tried turning the depth off but don't know whats wrong here - my movie files are just in the KB range. How can I play videos without lagging?

blue
  • 7,175
  • 16
  • 81
  • 179
  • 1
    Turn on the Profiler, start the game, wait for it to get laggy, and then pause the game and show us what is in the cpu usage timeline – Ruzihm Oct 31 '18 at 17:38
  • 1
    From my past experiment with the `VideoPlayer` API, it can only handle one video at a time. You try to load multiple videos with multiple `VideoPlayer`, you will run into lag or memory issues especially on mobile devices. Your option might be to use an expinse Video API from the assetstore or try not to use RenderTexture. Try to use the `RawImage` components to display the videos. – Programmer Oct 31 '18 at 18:04
  • @Programmer makes sense, thank you - so you'd recommend RawImage components? Or do you have a specific asset in mind? – blue Oct 31 '18 at 18:34
  • 1
    Yes, I recommend RawImage and that's what I use. See [here](https://stackoverflow.com/questions/41144054/using-new-unity-videoplayer-and-videoclip-api-to-play-video?s=3|72.4169) for an example. You can always set the Canvas to World Space if needed. – Programmer Oct 31 '18 at 18:37

1 Answers1

1

Based on the CPU taking 848ms per frame rendered, you are clearly bottlenecked on CPU. If you want to run at 30 frames per second, you'll need to get CPU time below 33ms per frame.

Since the CPU time is getting markedly worse after adding video players, it seems that the video codec is taxing your CPU heavily. Consider reducing the video quality as much as possible, especially reducing the resolution.

If that won't work, you may need to implement a shader-based solution using animated sprite sheets. That's more work for you, but it will run much more efficiently in the engine.

rutter
  • 11,242
  • 1
  • 30
  • 46