Forum rules - please read before posting.

Saving float LocalVariables in a "culture-invariant" way?

edited June 2022 in Technical Q&A

[Unity 2019.4.39f1 - AC v1.75.3]

Hi!

Recently we've received feedback about our game not being playable if your system's language is set to Turkish. This brought me to learn about a broad issue I was not familiar with, related to how strings are parsed and how one should consider using ToLowerInvariant() \ ToUpperInvariant() methods when parsing strings to avoid them being parsed incorrectly (or not at all) on different system languages.

I have partly fixed the issue, meaning that the game is now playable, but as I was testing my solution, I stumbled upon another, possibly related, issue.

All our scenes feature a bunch of float LocalVariables to control the speed of the Player's animation and movement. I noticed that if I:

  • Set my Thread.CurrentThread.CurrentCulture to, in this case, Turkish
  • Start playing and save the game
  • Comment out the code that switches my Thread.CurrentThread.CurrentCulture
  • Play the game and load that save game

The float values appear not to be parsed correctly from the serialized save data. Basically, what for me, in my Variables Manager, is set to "1.1" becomes 11, "1.4" becomes 14, etc.

Is there a way to address this already, in AdventureCreator that I'm not aware of?

Thanks a lot in advance, as always!

Comments

  • The manner in which save-data is stored depends on your platform - what are you building to, or does this occur in the Editor as well?

    If you open up the Save File Manager from the top of the Settings Manager, look for the Local Variables block of the scene in question, how are the values displayed? Share a screenshot if you're unsure how to read it.

  • It happens in the Editor as well.

    Here is a gallery of screenshots and the "steps" I take to let the issue arise. If you need more details please ask away!

    https://imgur.com/a/eh38iMy

    Thank you, in the meantime!

  • Recreated, thanks for the details.

    I'm a little conflicted on this one: the issue is fixable, but it will invalidate existing save games by breaking float values in cultures that use commas for decimal points (e.g. Turkish).

    As far as I can tell, the issue only occurs if you manually switch culture mid-game. Saving/loading when the culture is consistent produces no issue, regardless of which culture is active. It's also not - at least within AC - not necessary to switch culture as part of changing language. For what reason are you doing so?

  • edited June 2022

    The only reason I manually switched cultures was to troubleshoot the issue in the first place. I don't do it in the public build.

    The Turkish person that got in touch with me was not able to even run the game, so I asked for the Player.log. In it I noticed errors related to the fact that the uppercase "i"s were different and tried setting my CurrentCulture to Turkish to replicate the issue (thankfully it worked).

    In my code I was validating Enums by parsing strings collected from deserialized JSON files, but I was doing so using non culture-invariant functions.

    As a specific example, I had code lines such as:

    Category = (GarmentCategory)Enum.Parse(typeof(GarmentCategory), data.Category.ToUpper());

    that I turned into:

    Category = (GarmentCategory)Enum.Parse(typeof(GarmentCategory), data.Category.ToUpperInvariant());

    After fixing the issue, I removed all culture-changing code.

    I know that these would be specific case scenarios, but I have started thinking about (and actually I was also pointed out about it) situations where a person might switch computers that have different system languages (for whatever reason) and\or travel to different places, willing to continue playing the game.

    I actually thought about "forcing" a CurrentCulture as a solution, but I wondered whether it could have lead to all sorts of issues down the line, possibly more difficult to track

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.