Deactivate region specific behavior in C#?

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?

There’s a method overload for culture specific number parsing:

Invariant culture or en-US should both get the old behaviour back.

It depends on the .net-framework-version, not the unity version.

1 Like

Would it be possible to just set the culture to en-US in general? Where would I put this code?

[mention|MelEmdhoqxHUfLtwWiFUxQ==], isn’t this the same bug that was talked about here ? Wasn’t it supposed to be fixed?

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.

@Carpe-Denius is right. It is a change in the .net framework introduced in 4.x. You can set CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; at the start of the app or use float aValue = float.Parse("1.5", CultureInfo.InvariantCulture); . We fixed it in the editor wherever serialization was involved.

@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?

[InitializeOnLoad] does the trick.
You can use this script: Editor is using Window's locale settings