Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Official Running Linux Runtime without Window Manager workaround

Discussion in 'Linux' started by kalanasahabandu, Jun 20, 2023.

  1. kalanasahabandu


    Unity Technologies

    Apr 20, 2022
    Hello Unity Developers,

    I’m writing this post regarding a recent bug discovered by our forum users where running the Unity Linux Runtime without a Window Manager (Example: X11 Window Manager) result in mouse input to break (Example: Mouse cursor not appearing in the runtime). First of all we would like to thank our users for bringing this issue to our attention.

    After investigation we found out that, this issue was introduced with updating our SDL version. We rely on SDL to handle input related tasks in our engine. What is happening here is, Unity app is not rendering a cursor when running without a window manager using startx

    We have found a workaround that could help you:

    Note: This workaround require Unity Player to run in windowed mode.
    In case, the app needs to be run in full screen mode. We can trick the player to run in the display's native resolution by setting Default Screen Width and Default Screen Height parameters to match your display's native resolution.
    (Edit->Project Settings -> Player tab)

    Workaround : Forcing a cursor using Unity's Cursor.SetCursor API
    In the Start() function of your Unity script call Cursor.SetCursor API to set your cursor. This will force Unity app to render a cursor.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using System.Text;
    6. public class NewBehaviourScript : MonoBehaviour
    7. {
    8.     private Text box;
    9.     public Texture2D c1, c2; // load textures to these vars from the inspector window
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         box = GameObject.Find("box").GetComponent<Text>();
    14.         Cursor.SetCursor(c2, new Vector2(0, 0), CursorMode.ForceSoftware);
    15.     }
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         if(Input.GetKeyDown(KeyCode.W))
    20.         {
    21.             box.text = "W Pressed";
    22.         }
    23.         if(Input.GetKeyDown(KeyCode.A))
    24.         {
    25.             box.text = "A Pressed";
    26.         }
    27.     }
    28. }
    We thank you again for bringing this issue to our attention and please feel free to contact us in this thread if you have any questions or need further assistance.