1
votes

When navigating from menu to a Scene that contains 8, 1-minutes MP4 videos, that are played using new VideoPlayer script on RawImage component. I am using Unity 5.6.0b11 beta version.

In the scene that I am trying to navigate has prefabs that loads videos in list thumbnails, previously I was loading Images instead of Videos and it was working fine, now when trying to load video it freezes for than 38 seconds on Axon 7 (4GB RAM) and 32 seconds on One Plus 3 (6 GB RAM) but does not lags at all when playing on Unity Player itself.

Script I used for VideoPlayer is from this StackOverflow Question.

button.onClick.AddListener(new UnityEngine.Events.UnityAction(() =>
{
   SceneManager.LoadSceneAsync("SceneSponsors");
   StartCoroutine(CloseMenu());
}));

Is there a way, I can work around with the Slow Loading Scenes or pre-load them in Background when mainScene is loaded on the App start and navigate in need.

I saw somewhere Resources.Load() also makes it slow on Android Devices, but I've tested by removing all Resources.Load() which I was using to load image sprites but the problem was still there.

Edit: Here's my CloseMenu() functions it is only used to swipe and move the menu panel. P.S the App freezes only on loading that particular Scene, and works smoothly for other.

IEnumerator CloseMenu()
{
    if (IsOpen)
    {
        Vector3 pos = MainMenuWindow.transform.position;
        iTween.ColorUpdate(CloseArea, new Color(0, 0, 0, 0f), .6f);
        iTween.MoveTo(MainMenuWindow.gameObject, new Vector3(Screen.width, pos.y, pos.z), .6f);
        IsOpen = false;
        yield return new WaitForSeconds(.3f);
        CloseArea.transform.position = new Vector3(-240 * ScaleFact, CloseArea.transform.position.y, CloseArea.transform.position.z);
    }
}

Edit 2 I am loading VideoPlayer on RawImage using Script. Here's what RawImage looks like in Play mode along with VideoPlayer, and in inactive mode.

2
What does your CloseMenu function look like?Programmer
@Programmer I have added the function. BTW App freezes only on loading that particular Scene, and works smoothly for otherLuzan Baral
Hmm there is nothing much going on in the CloseMenu function. 38 seconds is too much. Please check codes that you run in the OnEnable, Awake or Start functions. Disable them all then re-enable them one by one. You will find which one causing the problem. Please, post that one.Programmer

2 Answers

2
votes

For my case of problem. I had to make some changes on the VideoPlayer API Script I was using from this StackOverflow Question

In the script I was using from that link. The Co-routine was started inside the Start() function, that made the videos in 8 different prefab, to load at once even they were in pause mode.

So I added a new function PlayVideoOnClick() and attached it to the Click Event of the RawImage, so now the video will be loaded only if the RawImage is clicked.

Changed from

public void Start()
{
    Application.runInBackground = true;
    StartCoroutine(playVideo());

}

To

public void PlayVideoOnclick()
{
    Application.runInBackground = true;
    StartCoroutine(playVideo());

}

P.S: You can also see my YouTube Video Tutorial and Blog on Playing Videos smoothly in Unity.

1
votes

It is a well known bug that loading big scenes using LoadSceneAsync may block the gpu completely several seconds (completely unnoticeable in the editor), i´ve also been following this for quite some time now,
From the forums:
https://forum.unity3d.com/threads/starting-async-load-causes-massive-lag-spike.288755/
Official unity Issue tracker:
https://issuetracker.unity3d.com/issues/loading-a-scene-async-creates-huge-performance-spikes-for-the-gpu