Search Unity

Question GameFoundation Can't be Initialized

Discussion in 'Game Foundation' started by Pepperoni92, Dec 4, 2019.

  1. Pepperoni92

    Pepperoni92

    Joined:
    Oct 26, 2014
    Posts:
    11
    Trying to incorporate GameFoundations into an existing project. Really like what the system promises to do.

    However, I cannot seem to get it initialized. When I try to initialize it in the Awake of one of my scene objects with GameFoundation.Initialize(), I receive a very vague warning in the console that say's:

    GameFoundation can't be initialized.
    UnityEngine.GameFoundation.GameFoundation:Initialize(IDataPersistence, Action, Action)


    Using Unity 2019.2.14f1 on MacOS
     
    Last edited: Dec 4, 2019
    erika_d likes this.
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    Thanks for reporting this issue.
    • Would you be able to provide the script where you're calling GameFoundation.Initialize()?
    • Would you also be able to provide your gameFoundationDatabase?
    • Also, are trying to initialize using dataPersistence or not (although we should be able to get that info from the script)?
    One way we've been able to reproduce this issue is by not having the game foundation database set in the gamefoundationsettings. Could you confirm if that resolves the issue for you?

    We are working on improving the error message to give more information about the error and how to resolve it.
     
    Last edited: Dec 5, 2019
    erika_d likes this.
  3. Pepperoni92

    Pepperoni92

    Joined:
    Oct 26, 2014
    Posts:
    11
    I've just placed the script below on an empty GameObject in my scene. But, you can download a very simple version of the project that presents the same error at this link.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.GameFoundation;
    3.  
    4. public class FoundationTest : MonoBehaviour
    5. {
    6.     private void Awake()
    7.     {
    8.         GameFoundation.Initialize();
    9.     }
    10. }
     
  4. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Hi @Pepperoni92,

    Are you still experiencing this issue? We tested with the project at the link you included above and weren't able to duplicate the issue. Can you double check that the GameFoundationSettings still has the GameFoundationDatabase linked as that's the easiest way to experience the error message you're getting. If it is linked, and you're still experiencing the issue, maybe you can create a support ticket by emailing game-foundation@unity3d.com so we can look into this in greater depth for you?
     
  5. Pepperoni92

    Pepperoni92

    Joined:
    Oct 26, 2014
    Posts:
    11
    Just tried it again in Unity 2019.2.15f1, and it seems to be working now. Perhaps something was fixed between versions.
     
    erika_d and mingz-unity like this.
  6. theworldin8dits

    theworldin8dits

    Joined:
    Jul 16, 2020
    Posts:
    8
    I'm trying to follow the YouTube Tutorial
    Using Game Foundation to Quickly Build Common Game System Unite Now 2020
    and I this happens
    InvalidOperationException: Error: GameFoundation.Initialize() must be called before the StoreView is used.
    UnityEngine.GameFoundation.UI.StoreView.ThrowIfNotInitialized () (at Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/UI/Runtime/StoreView.cs:533)
    UnityEngine.GameFoundation.UI.StoreView.Start () (at Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/UI/Runtime/StoreView.cs:198)
     
  7. theworldin8dits

    theworldin8dits

    Joined:
    Jul 16, 2020
    Posts:
    8
    Now I'm here
    'MemoryDataLayer' could not be found unity
     
  8. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Hi @theworldin8dits,

    It sounds like you've solved the "GameFoundation.Initialize() must be called before the StoreView is used." error already, for the MemoryDataLayer could not be found error could you please share your initialization code? Maybe it's missing the namespace?

    My initialization code looks like:
    Code (CSharp):
    1. using UnityEngine.GameFoundation;
    2. using UnityEngine.GameFoundation.DefaultLayers;
    3.  
    4. ...
    5.  
    6.     if (!GameFoundation.IsInitialized)
    7.     {
    8.           GameFoundation.Initialize(
    9.                 dataLayer: new MemoryDataLayer()
    10.            );
    11.     }
    Hope that helps!
     
    Last edited: Jul 17, 2020
    theworldin8dits likes this.
  9. theworldin8dits

    theworldin8dits

    Joined:
    Jul 16, 2020
    Posts:
    8
    Thank you so much Erika.
    using UnityEngine.GameFoundation.DefaultLayers;
    That wasn't included in the tutorial.
    It's up and running now.
     
    erika_d and mingz-unity like this.
  10. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Great, glad it helped! We're having some trouble getting the latest version of our docs posted right now, and I think that's been fixed in a more recent version, but we're working on it. Thanks for your patience!
     
  11. metiscoda

    metiscoda

    Joined:
    Nov 18, 2013
    Posts:
    41
    I have a similar problem where GameFoundation cannot initialize, and it gives me an issue with CurrencyExchangeObject not being found. I might be able to start over with a new db, but i have already entered a bunch of data and would rather not lose it:
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2.   at UnityEngine.GameFoundation.DefaultCatalog.CurrencyExchangeObject.Configure () [0x00000] in /Users/jimmy/Projects/hc-sudden-turn-copy/Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/DefaultCatalog/Runtime/CurrencyExchangeDefinitionObject.cs:36
    3.   at UnityEngine.GameFoundation.DefaultCatalog.TransactionExchangeDefinitionObject.Configure () [0x0001f] in /Users/jimmy/Projects/hc-sudden-turn-copy/Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/DefaultCatalog/Runtime/TransactionExchangeDefinitionObject.cs:94
    4.   at UnityEngine.GameFoundation.DefaultCatalog.VirtualTransactionAsset.ConfigureTransaction (UnityEngine.GameFoundation.CatalogBuilder builder) [0x0000e] in /Users/jimmy/Projects/hc-sudden-turn-copy/Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/DefaultCatalog/Runtime/VirtualTransactionAsset.cs:33
    5.   at UnityEngine.GameFoundation.DefaultCatalog.BaseTransactionAsset.ConfigureItem (UnityEngine.GameFoundation.CatalogBuilder builder) [0x00001] in /Users/jimmy/Projects/hc-sudden-turn-copy/Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/DefaultCatalog/Runtime/BaseTransactionAsset.cs:39
    6.   at UnityEngine.GameFoundation.DefaultCatalog.CatalogItemAsset.Configure (UnityEngine.GameFoundation.CatalogBuilder builder) [0x00001] in /Users/jimmy/Projects/hc-sudden-turn-copy/Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/DefaultCatalog/Runtime/CatalogItemAsset.cs:319
    7.   at UnityEngine.GameFoundation.DefaultCatalog.SingleCollectionCatalogAsset`1[TItemAsset].ConfigureCatalog (UnityEngine.GameFoundation.CatalogBuilder builder) [0x00019] in /Users/jimmy/Projects/hc-sudden-turn-copy/Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/DefaultCatalog/Runtime/SingleCollectionCatalogAsset.cs:386
    8.   at UnityEngine.GameFoundation.DefaultCatalog.BaseCatalogAsset.Configure (UnityEngine.GameFoundation.CatalogBuilder builder) [0x00001] in /Users/jimmy/Projects/hc-sudden-turn-copy/Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/DefaultCatalog/Runtime/BaseCatalogAsset.cs:57
    9.   at UnityEngine.GameFoundation.DefaultCatalog.GameFoundationDatabase.UnityEngine.GameFoundation.ICatalogConfigurator.Configure (UnityEngine.GameFoundation.CatalogBuilder builder) [0x00028] in /Users/jimmy/Projects/hc-sudden-turn-copy/Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/DefaultCatalog/Runtime/GameFoundationDatabase.cs:216
    10.   at UnityEngine.GameFoundation.DefaultLayers.BaseMemoryDataLayer.UnityEngine.GameFoundation.ICatalogConfigurator.Configure (UnityEngine.GameFoundation.CatalogBuilder builder) [0x00000] in /Users/jimmy/Projects/hc-sudden-turn-copy/Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/DefaultLayers/Runtime/BaseMemoryDataLayer_CatalogConfigurator.cs:29
    11.   at UnityEngine.GameFoundation.GameFoundation+<InitializeRoutine>d__28.MoveNext () [0x000ea] in /Users/jimmy/Projects/hc-sudden-turn-copy/Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/Core/Runtime/GameFoundation.cs:188
    12. Rethrow as Exception: GameFoundation failed to initialize runtime catalogs from editor catalogs
    13.  
    14. UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
    15. UnityEngine.DebugLogHandler:LogException(Exception, Object)
    16. UnityEngine.Logger:LogException(Exception, Object)
    17. UnityEngine.Debug:LogException(Exception)
    18. UnityEngine.GameFoundation.<InitializeRoutine>d__28:MoveNext() (at Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/Core/Runtime/GameFoundation.cs:194)
    19. UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)
    20. UnityEngine.MonoBehaviour:StartCoroutineManaged2(IEnumerator)
    21. UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Scripting/MonoBehaviour.bindings.cs:91)
    22. UnityEngine.GameFoundation.GameFoundation:Initialize(IDataAccessLayer, Action, Action`1) (at Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/Core/Runtime/GameFoundation.cs:117)
    The Error: Game Foundation failed to initialize comes right after this.
     
  12. metiscoda

    metiscoda

    Joined:
    Nov 18, 2013
    Posts:
    41
    Not sure how I messed it up, but here it is attached for you to take a look at if you'd like:
     

    Attached Files:

  13. mingz-unity

    mingz-unity

    Unity Technologies

    Joined:
    Oct 12, 2017
    Posts:
    63
    Thanks for reaching out to us @metiscoda

    I was able to reproduce your error log using the database you uploaded. Looks like there's a particular virtual transaction item called 'Buy Taxi' which has an empty Currencies (but has an amount), which is the source of the crash.

    upload_2020-8-6_0-24-2.png

    You should be able to initialize correctly if that empty currency is filled or removed. Please make sure to fill in the currency field when you define transactions. In the meanwhile, I feel our error log is not too informative helping you to catch the root cause here, so I'll discuss with the team to improve on this one.

    Thanks for using Game Foundation.
     
  14. metiscoda

    metiscoda

    Joined:
    Nov 18, 2013
    Posts:
    41
    Thanks for the quick solution - I verified that it works! Yeah a better error message would be good. If I may make a suggestion, it would be awesome if we could import and export these entries to text files as currently the data entry is a bit onerous even with the limited data I had. But all in all thankful for this product. Cheers!
     
    jrmobley, mingz-unity and erika_d like this.
  15. theworldin8dits

    theworldin8dits

    Joined:
    Jul 16, 2020
    Posts:
    8
    gamefoundation.JPG Hi, I'm using unity 2020.1.3f1.
    I imported Game Foundation package Version 0.6.0-preview.2 - July 02, 2020
    without importing any samples.
    but I didn't find the UI parts or the Store.
    I dragged the Grid Store prefab from the

    Library\PackageCache\com.unity.game.foundation@0.6.0-preview.2\UI\Prefabs\Store\Items"

    and tried to enter play mode and I get this error.


    InvalidOperationException: Error: GameFoundation.Initialize() must be called before the StoreView is used.
    UnityEngine.GameFoundation.UI.StoreView.ThrowIfNotInitialized () (at Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/UI/Runtime/StoreView.cs:535)
    UnityEngine.GameFoundation.UI.StoreView.Start () (at Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/UI/Runtime/StoreView.cs:198)
     
    Last edited: Sep 15, 2020
  16. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Hi @theworldin8dits,

    You'll need a script attached to an object in the scene that initializes Game Foundation before the prefabs initialize. (Likely during Awake; normally we suggest initializing Game Foundation in Start, but when working with prefabs, sometimes Start doesn't trigger in time depending on how the prefab is in the scene). I know you said you didn't import any samples, but if you did want to see a sample with it, you can find examples in Samples 8 and 11 from the latest release.
     
    mingz-unity likes this.
  17. theworldin8dits

    theworldin8dits

    Joined:
    Jul 16, 2020
    Posts:
    8
    Still stuck.
    Here's the code.

    using UnityEngine;
    using UnityEngine.GameFoundation;
    using UnityEngine.GameFoundation.DefaultLayers;

    public class Init : MonoBehaviour
    {
    private void Awake()
    {
    GameFoundation.Initialize();
    if (!GameFoundation.IsInitialized)
    {
    GameFoundation.Initialize(
    dataLayer: new MemoryDataLayer()
    );
    }
    }
    }



    gamefoundation.JPG
     
  18. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Hi @theworldin8dits

    You're getting a compilation error because we don't have an override for GameFoundation.Initialize that accepts 0 arguments.

    Code (CSharp):
    1. private void Awake()
    2. {
    3.     GameFoundation.Initialize(); // REMOVE THIS LINE
    4.     if (!GameFoundation.IsInitialized)
    5.     {
    6.         GameFoundation.Initialize(
    7.              dataLayer: new MemoryDataLayer()
    8.          );
    9.     }
    10. }
     
  19. geg8285

    geg8285

    Joined:
    Sep 30, 2015
    Posts:
    6
    Hi all, I have the same issue,

    I have installed the latest version of GameFoundation and tried to use samples that were included on it.
    When I run someone of the attached examples I got an exception:


    InvalidOperationException: Error: GameFoundation.Initialize() must be called before the InventoryManager is used.
    UnityEngine.GameFoundation.InventoryManager.ThrowIfNotInitialized () (at Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/Core/Runtime/InventoryManager.cs:406)
    UnityEngine.GameFoundation.InventoryManager.CreateItem (System.String key) (at Library/PackageCache/com.unity.game.foundation@0.6.0-preview.2/Core/Runtime/InventoryManager.cs:673)
    UnityEngine.GameFoundation.Sample.InventoryBasics.Start () (at Assets/Samples/Game Foundation/0.6.0-preview.2/01 Inventory Basics/InventoryBasics.cs:82)

    I tried to add an object on the scene with force initialization on Awake as described above, but the same result occurs.
    I tried to debug the inventory basics sample (InventoryBasics.cs)

    Code (CSharp):
    1.         private void Start()
    2.         {
    3.             // The database has been properly setup.
    4.             m_WrongDatabase = !SamplesHelper.VerifyDatabase();
    5.             if (m_WrongDatabase)
    6.             {
    7.                 wrongDatabasePanel.SetActive(true);
    8.                 return;
    9.             }
    10.  
    11.             // - Initialize must always be called before working with any game foundation code.
    12.             // - GameFoundation requires an IDataAccessLayer object that will provide and persist
    13.             //   the data required for the various services (Inventory, Wallet, ...).
    14.             // - For this sample we don't need to persist any data so we use the MemoryDataLayer
    15.             //   that will store GameFoundation's data only for the play session.
    16.            GameFoundation.Initialize(new MemoryDataLayer()); ====> in this line executed but it is not initialize in real
    17.  
    18.             // Here we bind a listener that will set an inventoryChanged flag to callbacks on the Inventory Manager.
    19.             // These callbacks will automatically be invoked anytime an item is added or removed.
    20.             // This prevents us from having to manually invoke RefreshUI every time we perform one of these actions.
    21.             InventoryManager.itemAdded += OnInventoryItemChanged;
    22.             InventoryManager.itemRemoved += OnInventoryItemChanged;
    23.  
    24.             // The Inventory Manager starts with initial allocation of 2 apples and 1 orange, but we
    25.             // can add an additional orange here to get us started.
    26.             InventoryManager.CreateItem("orange"); [B]====> [/B] failed here with exception that described above
    27.  
    28.             RefreshUI();
    29.         }



    My unity version is 2019.3.4f1
    GameFoundation version is 0.6.0

    Thanks!
     
  20. theworldin8dits

    theworldin8dits

    Joined:
    Jul 16, 2020
    Posts:
    8
    Thank you Erika
    You've been of great help.
    I hadn't progressed since July.
     
    erika_d likes this.
  21. theworldin8dits

    theworldin8dits

    Joined:
    Jul 16, 2020
    Posts:
    8
    Try removing game foundation.
    Then reimporting it.
    With the samples
    attach the store prefabs from Packages>GameFoundation>UI>Prefabs Store
    Create a script
    using UnityEngine;
    using UnityEngine.GameFoundation;
    using UnityEngine.GameFoundation.DefaultLayers;

    public class Init : MonoBehaviour
    {
    private void Awake()
    {
    if (!GameFoundation.IsInitialized)
    {
    GameFoundation.Initialize(
    dataLayer: new MemoryDataLayer()
    );
    }
    }
    }

    Attach it to an empty game object
    Then go to Window>GameFoundation>Settings>Runtime Settings
    Click Purchasing Enabled and/or Editor Analytics
     
  22. theworldin8dits

    theworldin8dits

    Joined:
    Jul 16, 2020
    Posts:
    8
    Thank you again.
     
    erika_d likes this.
  23. geg8285

    geg8285

    Joined:
    Sep 30, 2015
    Posts:
    6

    Hi,
    I re-imported the package with samples but the same issue occurs.

    Sorry, but I don't understand how the store prefab related to InventoryBasics sample?
    I did debug for InventorySample.cs and it looks like the line with initialization executed successfully, but really initialization not happened, because it fails in the next line.

    GameFoundation.Initialize(new MemoryDataLayer()); ====> executed but realy it is not initialize the game foundation object
    InventoryManager.CreateItem("orange"); ====> failed here with exception that described above

    The issue happened when I import the package to the existed project. (I try to integrate the game foundation to my game)
    If I import it to the new project it is works correct.
    Any suggestions about why it is happening?


    Thanks!
     
    Last edited: Sep 18, 2020
    erika_d likes this.
  24. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Hi @geg8285

    So to clarify, if you import the sample scenes into a blank project, the InventoryBasics sample works correctly, but if you import the sample scene into an existing project, you get the `GameFoundation.Initialize() must be called before the InventoryManager is used` error?

    I wasn't able to duplicate this in my test project, so some questions:

    - Can you confirm the version of Game Foundation and Unity you are using?
    - Are the other sample scenes having the same issue?
    - Have you added anything to the InventoryBasics sample scene (a Game Foundation prefab for example, could cause this)?
    - Can you make sure the GameFoundationDatabaseSettings is pointing to the SampleDatabase (although if it weren't you should be getting a different error)
    - Do you have a different project that you could try importing the samples too and see if the same thing happens?
    - When you reimported the samples, did you first delete the samples already in your project?

    Since it worked in your blank project, and you tried deleting it in your existing project it seems like maybe some cache held onto something when you tried deleting. Maybe try deleting only the "00 Database and Assets" and "01 InventoryBasics" samples (instead of the whole package and all the samples), restart Unity, and reimport both of the samples?
     
  25. geg8285

    geg8285

    Joined:
    Sep 30, 2015
    Posts:
    6
    Thank you, all works well after doing this:
    "Then go to Window>GameFoundation>Settings>Runtime Settings
    Click Purchasing Enabled and/or Editor Analytics"
     
    erika_d and mingz-unity like this.