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. Dismiss Notice

Deactivate region specific behavior in C#?

Discussion in '2019.1 Beta' started by Ravery, Mar 25, 2019.

  1. Ravery

    Ravery

    Joined:
    Mar 5, 2016
    Posts:
    46
    In 2018 I could float.Parse("1.5"), which would give me a 1.5f.
    In 2019.1.0b8 it returns 15.

    I guess it's the system localization (working on a German Windows 10), but I'm not sure.
    How can I deactivate it and make sure no scripts will ever deviate from English behavior no matter what language/region a player's OS is?

    I'm not even sure what kind of things are affected by this forced localization besides number conversion. Is there any list?
     
  2. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    bobdonovan likes this.
  3. Ravery

    Ravery

    Joined:
    Mar 5, 2016
    Posts:
    46
    Would it be possible to just set the culture to en-US in general? Where would I put this code?
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,195
    @bobdonovan, isn't this the same bug that was talked about here? Wasn't it supposed to be fixed?
     
  5. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Not tested, but it should be somewhere static at CultureInfo.CurrentCulture
    You can set this at app start, preferably before any parsing happens.

    In-editor behaviour is fixed.
     
  6. bobdonovan

    bobdonovan

    Unity Technologies

    Joined:
    Aug 2, 2017
    Posts:
    14
    @Carpe-Denius is right. It is a change in the .net framework introduced in 4.x. You can set
    Code (CSharp):
    1. CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
    at the start of the app or use
    Code (CSharp):
    1. float aValue = float.Parse("1.5", CultureInfo.InvariantCulture);
    . We fixed it in the editor wherever serialization was involved.
     
  7. Ravery

    Ravery

    Joined:
    Mar 5, 2016
    Posts:
    46
    @bobdonovan @Carpe-Denius
    Thanks.
    How do I make sure it's at the start of the app? Just have some script and put it on the top of execution order or something else?
     
  8. bobdonovan

    bobdonovan

    Unity Technologies

    Joined:
    Aug 2, 2017
    Posts:
    14