Search Unity

Switching between items in an array?

Discussion in 'Scripting' started by alexroflol, Apr 29, 2019.

  1. alexroflol

    alexroflol

    Joined:
    Apr 18, 2018
    Posts:
    16
    I am trying to play a sequence of videos to play in a 'choose your own adventure' style game, and I need to prepare the videos in separate players for transitions to be seamless.

    There will always be two options to choose from, so I have created three video players - one for the currently playing video and two to prepare the videos for each option.

    I'm having trouble getting my head around what code I should be writing to change the active player and prepare the other two whenever a choice is made.

    Sorry if that's a bit confusing, please let me know of there's any more info I can provide to help you help me! Thanks.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    Does whatever system you're using for video playback even support "preparing" a video for play?

    Looking at the Unity VideoPlayer, there's a bunch of examples. Do any of those get you where you want?

    https://docs.unity3d.com/ScriptReference/Video.VideoPlayer.html

    It looks like there's a field called .playOnAwake you can clear to make it not start until you call .Play(). No guarantee that when you hit .Play() it will play seamlessly either, such as no blank frames, etc.

    Be forewarned: Video playing is extremely finnicky and depending on things such as video format, video drivers, integration with underlying operating system calls, etc. While you might get it "seamless" on one platform or computer, it is highly likely it will not be seamless on all platforms.
     
  3. alexroflol

    alexroflol

    Joined:
    Apr 18, 2018
    Posts:
    16
    Thanks for the response! I'm using the Videoplayer.Prepare() function to prep the videos - this seems to work okay in the test i did where i created a video player for each video and prepared them all on Start.

    This approach made the video change seamless across my target platforms (at least over a couple of tests!), but it is unmanageable for the full game where i may have 50+ that need to be prepared.

    My solution was to only prepare the videos required for the next branching options at runtime, and that way reduce the players required from one per video to just three. Does that make sense? I can post some screens of my project if that will help!