Search Unity

Steam overlay and Application.OpenURL()

Discussion in 'Editor & General Support' started by Robdon, Feb 22, 2021.

  1. Robdon

    Robdon

    Joined:
    Jan 10, 2014
    Posts:
    141
    I'm having a problem with using Application.OpenURL().

    I use it in our game to link to our FB and Twitter pages with buttons, and also in the credits to our own website etc.

    This all works fine in Windows and Mac.

    I'm having problems specifically on Linux (Ubuntu 18.04 x86_64), Unity 2019.4.20f1.

    When I issue an OpenURL on Linux, then it does not open Chrome and go to the URL. It seems it 'tries' to open Chrome, but then it crashes about 60 seconds later.

    I know it's openning Chrome, cause I have a log in the startup script: /usr/bin/google-chome and it does start. Stracing the chrome process is difficult, but it does seem to be doing some kind of communication with the SteamAPI and shared memory for some reason. But I can't quite see what goes wrong.

    At the same time as the OpenURL getting called, I get some errors in my Player.log:
    ERROR: ld.so: object '/home/rob/.steam/ubuntu12_32/gameoverlayrenderer.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.

    It seems that it is trying to use the 32 bit version of gameoverlayrenderer.so, rather than the 64 bit one (it is in .../ubuntu12_64/)

    The overlay works normally in the game, with shift tab etc. It's just when trying to go to s URL it causes a problem.

    If I run the game outside of steam and disable the api, then it works fine.

    I can repo it in a blank Unity project, with just a Application.OpenURL("") in it, so it's nothing that complicated to cause.

    Anyone else seen this, or know of any workaround?
     
  2. DaveKap

    DaveKap

    Joined:
    Mar 6, 2013
    Posts:
    94
    This is, unfortunately, a very late answer but in case anyone in the future needs the solution, my very intelligent friend Matias G figured out the solution to this.

    It turns out that when you try to use the OpenURL call in a Unity game while the Steam Overlay is active, Steam tries to inject the overlay into Chrome. Chrome, however, has anti-temper measures that fight with this injection, causing the lag that you see. Steam is messing with LD_PRELOAD or graphics APIs to get the overlay rendered on top of Chrome. Thus, the following solution:
    Code (CSharp):
    1. #if UNITY_STANDALONE_LINUX
    2.         string oldVar = Environment.GetEnvironmentVariable("LD_PRELOAD");
    3.         Environment.SetEnvironmentVariable("LD_PRELOAD", null);
    4.         Application.OpenURL("url");
    5.         Environment.SetEnvironmentVariable("LD_PRELOAD", oldVar);
    6. #else
    7.         Application.OpenURL("url");
    8. #endif
    This will ensure that if the Linux version of your game is running, it will nullify the LD_PRELOAD environmental variable and prevent Steam from trying to push its overlay onto the Chrome window being opened up, eliminating the lag and allowing games run on Linux to use the Steam Overlay again.

    Hope this helped somebody!
     
    Robdon and Joe-Censored like this.
  3. Robdon

    Robdon

    Joined:
    Jan 10, 2014
    Posts:
    141
    Nice find, thanks for posting. That does indeed fix it! :)