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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Bug Currency Initial Allocation not saving

Discussion in 'Game Foundation' started by Renea, May 6, 2020.

  1. Renea


    Nov 12, 2017
    I've started going through the getting started tutorials and when working the currency portion of the tutorial, I get a warning and incorrect information during runtime. Below are pictures of what I'm seeing.

    Currency Window showing my created item
    Currency window.PNG

    Warning at start of runtime

    Debug log messages. The first one that is highlighted is the initial steps of the currency code, where the second shows that the currency changed. I used the default value of 50 that was used in the tutorial. With this I would expect the initial balance to be 100 and the new balance to be 150, but instead I see an initial balance of 0 and a new balance of 50.
    Balance log entries.PNG
  2. antoine-agthe_unity


    Unity Technologies

    Jun 6, 2019
    Hello Renea.
    Thanks for your documented feedback.

    TL;DR: Can you tell me if you load an existing player profile, or if you have this bug when you start a fresh profile?

    The first warning you see is not something you should be afraid of.
    It is displayed when Game Foundation loads a profile which doesn't contain any entry for a
    A warning is displayed, but GF just initializes the value to
    Internally, in the team, we're thinking of turning this warning into a simple log.
    At the moment, this info looks like more than a log.
    What do you think?

    Now, why initializing the value to
    , instead of the
    initial allocation
    It is because this allocation is used only when a new player profile is created.
    If you player profile already exists, it doesn't apply.
    This behaviour fits with our ChilliConnect backend:
    If you want to know more about ChilliConnect, you'll find a dedicated sample in the Package Manager (Sample 9).

    Can you share a code snippet of the way you initialize Game Foundation?
    It can help me figuring out what happens.
  3. Renea


    Nov 12, 2017
    Hello Antoine,

    Thank you for responding so quickly.

    When you say "player profile" are you talking about Unity Editor player or an in game player character? If you mean game player character profile, I fear I may have missed something in the tutorials about creating a player profile. I say this based on the explanation you have about the warning message. I initially thought it to be just as you said that it is something that GF displays before it gets to the code for the currency information, but when I went through the tutorial and it showed that I should be seeing the initial allocation in the first log message it concerned me and wandered if the warning message had anything to do with this behaviour. See below snipit.

    Side Note: the link to the "next tutorial" at the end of this page that is supposed to go to the debugger window tutorial is broken.

    currency tutorial.PNG

    I created a brand new Unity 2019.3.12f1 3D project and imported the latest Game Foundation (0.4.0) from package manager and immediately started the tutorials listed here:

    Attached is my full GameManager.cs file for your review. I've completed up through tutorial 8 in the above link, just after the stats tutorials (just to give you an idea of where I'm at in the code). Here is a snip of the awake method showing my GF initialization.

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.GameFoundation;
    6. using UnityEngine.GameFoundation.DataAccessLayers;
    7. using UnityEngine.GameFoundation.DataPersistence;
    9. /// <summary>
    10. /// Following the tutorials at
    11. /// This is how the GameManager is set up.
    12. /// The only exception is the Singleton Base class which was retrieved from:
    13. /// </summary>
    14. public class GameManager : Singleton<GameManager>
    15. {
    16.     private void Awake()
    17.     {
    18.         // this data layer will not save any data, it is usually used for examples or tests
    19.         IDataAccessLayer dataLayer = new MemoryDataLayer(GameFoundationSerializableData.Empty);
    21.         GameFoundation.Initialize(dataLayer, onInitializeSucceeded, onInitializeFailed);
    23.     }
    25.     private void onInitializeFailed(Exception obj)
    26.     {
    27.         Debug.LogException(obj);      
    28.     }
    30.     private void onInitializeSucceeded()
    31.     {
    32.         Debug.Log("Game Foundation is Successfully Initialized!");
    34.         #region Inventory

    Attached Files:

    mingz-unity likes this.
  4. antoine-agthe_unity


    Unity Technologies

    Jun 6, 2019
    OK, I see.
    The problem comes from line 19.

    You are initializing your
    explicitly with an
    That means you want to have nothing in your profile.
    That is why you were having the warning log.
    GameFoundation finds no record for your currency, and initializes to

    But if you use this statement instead...
    Code (CSharp):
    1. var dataLayer = new MemoryDataLayer(); // default constructor
    ... then you should be OK.

    Behind the scene, the
    asks the
    to create a default player data, including the initial allocations.

    The documentation is probably not very clear about using
    I put a pin on it.

    Now regarding the player profile, as you use the
    , then you didn't miss anything.
    By player profile, I mean a
    is initialized with this data, as it represents the data you want to manipulate.

    After a game session, if you want to save the profile, you can get the data object by calling

    Then you can save this data the way you want.

    Now if you want this data save/load to be done by GameFoundation, consider using
    You can initialize one by pointing a file in your system. It will save to this file by calling
    mingz-unity likes this.
  5. Renea


    Nov 12, 2017
    Thanks for the clarification. This helps me understand the system better.