Debug.Log deosn't work when called inside Video.EventHandler

Hello, I hope somebody can hep me understand this issue I am having.

I am using the following code to play a video clip when it has been prepared by the VideoPlayer, using the prepareCompleted event and the Prepare() function.

The code works and the video works as expected. This is my code:

using UnityEngine;
using UnityEngine.Video;
using System.Collections;

public class PlayVideo : MonoBehaviour
{
    VideoPlayer _arVideoPlayer;

    // Start is called before the first frame update
    void Awake()
    {
        Debug.LogWarning("Video Prefab Instantiated!!!");
        _arVideoPlayer = GameObject.Find("VideoPlayer").GetComponent<VideoPlayer>();
        _arVideoPlayer.prepareCompleted += PlayVideoWhenReady;
        _arVideoPlayer.Prepare();
    }

    void PlayVideoWhenReady(VideoPlayer vPlayer)
    {
        Debug.LogWarning("Video is ready to play!!!"); //THIS DOES NOT PRINT IN CONSOLE OR LOGCAT
        vPlayer.Play();
    }

}

However, the line Debug.LogWarning("Video is ready to play!!!"); inside the PlayVideoWhenReady() function doesn’t run (although the video plays correclty which means the play function is called).

Can anybody explain why???

Many Thanks

Michele

Might be related to it being on a different thread, but usually Debug.Log() works.

Did you place a breakpoint there and attach the debugger and see if the callback is called?

Also, make sure your log console selector buttons are enabled. See this graphic:

1 Like

Thanks @Kurt-Dekker it is definitely not a problem of the console setup as I don’t see the debug message in Logcat either, but I do see the debug massage in the Awake function.

The issue of it being in another thread is more plausible.

Do you know how to handle this situation? Why is it not printing if in another thread and what is the correct way of handling this?

Many thanks

I’ve never seen Debug.Log NOT show up, even from another thread, so my inclination is to think you are never getting the callback. Did you put a breakpoint in there and see it stop on the breakpoint?

1 Like

If the problem is really caused by Debug.Log not working on some separate thread special case, you could consider creating a string ConcurrentQueue, and add your log message to that queue. In Update() you check if anything is in the ConcurrentQueue, and write it to Debug.Log there from the main thread. Just an idea.

1 Like