Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by BenoitFreslon · Feb 02, 2017 at 06:53 PM · inputscenemousedetectionmouseclick

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)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BenoitFreslon · Feb 03, 2017 at 11:53 AM 0
Share

EDIT: Input.Get$$anonymous$$ouseButton(0) is not triggered too.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by BenoitFreslon · Feb 06, 2017 at 12:07 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by HenryStrattonFW · Feb 02, 2017 at 09:29 PM

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");
     }
 
 }
 

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BenoitFreslon · Feb 03, 2017 at 11:53 AM 0
Share

I already tried to use Get$$anonymous$$ouseButton and store the status in a static variable.

I use this code in the Update method in a persistant GameObject

 GameObject.DontDestroyOnLoad(gameObject);

in the Update method:

                 if ( Input.Get$$anonymous$$ouseButton ( 0 ) )
                     Debug.Log ( "$$anonymous$$ouseButton pressed" );
                 if ( Input.Get$$anonymous$$ouseButtonDown ( 0 ) )
                     Debug.Log ( "$$anonymous$$ouse button down" );
                 if ( Input.Get$$anonymous$$ouseButtonUp ( 0 ) )
                     Debug.Log ( "$$anonymous$$ouse button up" );

But the Input.get$$anonymous$$ouseButton is never triggered when I release the mouse button in the new scene.

avatar image HenryStrattonFW BenoitFreslon · Feb 04, 2017 at 01:03 PM 0
Share

I've updated my answer with some more information I've found out from testing. Seems the only way to achieve reliable mouse event tracking over the load is to load the scene additively.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

102 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to control global mouse 0 Answers

Left Mouse doesn't register click when keyboard button is pressed 1 Answer

Stops detecting continuous keyboard Input after the first scene change to that scene. 1 Answer

How can I disable mouse input completely? 3 Answers

How do I use Input.GetButton, instead of OnMouse() 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges