Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Issue listening for mouse clicks

Discussion in 'Unity Render Streaming' started by opamped, Apr 20, 2021.

  1. opamped

    opamped

    Joined:
    Oct 3, 2015
    Posts:
    6
    I'm looking for a straightforward way to respond to mouse clicks on a UI widget (image, etc) that leverages existing Unity functionality. I have outlined some unsuccessful attempts below.

    Unity 2020.2.6f1
    Render streaming Version 3.0.1-preview
    WebRTC Version 2.3.3-preview
    Input System Version 1.0.2

    1. Listen for LMB release in Update()

    Code (CSharp):
    1.     void Update()
    2.     {
    3.  
    4.         if (remoteDeviceManager.m_mouse.leftButton.wasPressedThisFrame)
    5.         {
    6.             Debug.Log("LEFT MOUSE DOWN IN UPDATE");
    7.         }
    8.         if (remoteDeviceManager.m_mouse.leftButton.isPressed)
    9.         {
    10.             Debug.Log("LEFT MOUSE IS HELD");
    11.         }
    12.         if (remoteDeviceManager.m_mouse.leftButton.wasReleasedThisFrame)
    13.         {
    14.             Debug.Log("LEFT MOUSE RELEASE IN UPDATE");
    15.         }
    16.     }
    Result:
    Mouse down and mouse hold register consistently when streaming. Mouse up fails to register ~90% of the time when streaming
    upload_2021-4-19_19-20-53.png

    2. Use UnityEngine.EventSystems

    Code (CSharp):
    1. // Remote mouse made current with Mouse.MakeCurrent();
    2.     public void OnPointerClick(PointerEventData eventData)
    3.     {
    4.         Debug.Log($"POINTER CLICK ON GAMEOBJECT gameobject={this.gameObject.name}");
    5.     }
    Result:
    No logs left when streaming from browser

    Next ideas are
    1. Track mouse state in FixedUpdate based only off of Mouse.LeftMouseButton.isPressed (this feels a little hacky but might be the best bet)
    2. Try and process input events manually by changing the input update mode in Project Settings
    3. Try and move most of the UI to the web side.
    Still a good chance I'm missing something simple though so I'd like to ask;

    Does anyone have a reliable way to implement mouse click events in render streaming on the Unity side?
     

    Attached Files:

    Last edited: Apr 20, 2021