Detect mouse inputs when the scene is changing to another scene.

Hello,

I need to detect if the player is still pressing the mouse or not when the Scene is changing.
If you reproduce these steps:

  1. Press the mouse button

  2. Change scene

  3. Release the button < This event is not detected with

    Input.GetMouseButtonUp(0)

You could try altering your logic a bit, instead of using GetMouseButtonUp and GetMouseButtonDown instead use GetMouseButton (returns true if mouse currently down, false otherwise) and then set your own flag based on that to allow you to respond to the discrete up/down moments instead of the continuous up or down state.

EDIT: Of course you’d need to make sure that the flag you store is being stored somewhere that will persist scene changes.

EDIT2:

So I tried to write up a test case for this, and here’s what I found, when you do a scene load with single mode, be it sycnronous or asynchronous, Input manager seems to undergo some sort of reset event, triggering making it impossible to reliably track the mouse press/release over the scene load.
However if you load the new scene additively, then the Input manager does not get the same reset event and you can track the mouse events over the load.

Not sure if that information is useful at all in any way, perhaps you can fashion a scenario where you additively load the next scene, and then unload the previous once the mouse up event has occurred, little bit of an ugly workaround true but it might be the only way. If anyone is interested here was the code for my test case.

using UnityEngine;
using UnityEngine.SceneManagement;

public class MouseTest : MonoBehaviour
{
    private bool m_MouseDown;

    void Awake()
    {
        DontDestroyOnLoad(gameObject);
    }

    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            if (!m_MouseDown)
            {
                m_MouseDown = true;
                _OnMouseDown();
            }
        }
        else
        {
            if (m_MouseDown)
            {
                m_MouseDown = false;
                _OnMouseUp();
            }
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            SceneManager.LoadSceneAsync("TestSceneB", LoadSceneMode.Additive);
        }
    }


    private void _OnMouseDown()
    {
        Debug.Log("Mouse Down");
    }

    private void _OnMouseUp()
    {
        Debug.Log("Mouse Up");
    }

}

I found a workaround:

On a mobile game we can use:

Input.touchCount

So we can detect if the user is still touching the screen during the scene transition.