Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug System.Environment.GetEnvironmentVariables() always returns null on Unity 2019 versions

Discussion in 'Linux' started by pmalachowskydeka, Sep 24, 2019.

  1. pmalachowskydeka

    pmalachowskydeka

    Joined:
    Mar 11, 2019
    Posts:
    1
    TL;DR 'System.Environment.GetEnvironmentVariables()' always returns null in 2019 releases (running on Ubuntu 16.04). I got System.Environment.GetEnvironmentVariables() to work in 2018 versions by opening up Unity Hub from the command-line. 2019 seems to open the editor differently (effectively killing the Hub parent process) which means that strategy doesn't work in any more. HELP!

    ----

    I discovered that in 2018 versions of the Unity Linux editor (running on Ubuntu 16.04) I could only get System.Environment.GetEnvironmentVariable() to return anything if I launched the editor from the command-line.

    I.e. I would run the following command from a terminal:
    cd ~/Unity/Hub/Editor/2018.3.12f1/Editor && ./Unity

    Forgive the crudeness, but I reasoned this worked because this allowed the editor process to be attached to that terminal's environment, which contained the correct environment variables. This gave the added benefit that also any process launched from the editor (using System.Diagnostics.ProcessStartInfo and System.Diagnostics.Process.Start()) would also have access to the correct environment variables.

    That explanation seems valid with what the docs on GetEnvironmentVariable() say:
    "On MacOS and Linux, the GetEnvironmentVariables method retrieves the name and value of all environment variables that are inherited from the parent process that launched the dotnet process or that are defined within the scope of the dotnet process itself."

    Now it seems that launching 2019 versions of the editor from the command line works differently. It looks like now once I click on a project to open it, the process I initiated from the command-line to open the Hub is terminated. The terminal outputs:

    "Parent process [24230] was terminated"

    Then once the editor launches (in some process invisible to me), my System.Environment.GetEnvironmentVariable() calls return nothing. Are there any workarounds? Is this a bug that can be fixed?
     
    Last edited: Oct 8, 2019
    LordOfLard likes this.
  2. qumeta

    qumeta

    Joined:
    Jun 10, 2020
    Posts:
    2
    when fix?
     
    LordOfLard likes this.
  3. MHR_171

    MHR_171

    Joined:
    Apr 1, 2015
    Posts:
    7
    Does it fixed?
     
  4. IsaiahBenodin

    IsaiahBenodin

    Joined:
    May 2, 2023
    Posts:
    2