Search Unity

Help Wanted How to access Mutable Properties?

Discussion in 'Game Foundation' started by Shaky6bones, Sep 8, 2020.

  1. Shaky6bones

    Shaky6bones

    Joined:
    Apr 21, 2016
    Posts:
    4
    Greetings! I'm having great success using Game Foundation for my inventory system. However, I can't figure out how to access the "Mutable Properties".

    GetStaticProperty(propertyKey)
    works great to access Static Properties, but I don't see an equivalent for Mutable Properties.

    The Game Foundation 0.6.0-preview.2 Tutorial 09 uses
    GetProperty(propertyKey)


    However, this method does not exist for me (Unity v.2019.4.9f1; Game Foundation v.0.6.0).

    I assume that the answer is very simple, but I haven't been able to figure it out thus far. Thank you for any assistance you can offer!
     
    erika_d likes this.
  2. mingz-unity

    mingz-unity

    Unity Technologies

    Joined:
    Oct 12, 2017
    Posts:
    59
  3. Shaky6bones

    Shaky6bones

    Joined:
    Apr 21, 2016
    Posts:
    4
    Thank you for pointing me to the tutorial. As I mentioned in my original post, this tutorial suggests using GetProperty(propertyKey). I understand that. However, this method isn't available for me to use (see pic).



    I'm afraid that I may have somehow corrupted something, but I don't understand your package well enough to be able to troubleshoot it. I tried removing the package and reinstalling it, but the problem persists.

    Can you please point me to the likely location of the problem?
     
  4. mingz-unity

    mingz-unity

    Unity Technologies

    Joined:
    Oct 12, 2017
    Posts:
    59
    I see. Mutable Properties are only available on Inventory Items. Are you trying to access them on other types?
     
  5. Shaky6bones

    Shaky6bones

    Joined:
    Apr 21, 2016
    Posts:
    4
    No. This definition is for an InventoryItem. As you see, the GetStaticProperty() line above works just fine, and GetDefaultProperties() is also accessable.

    I have:

    Code (CSharp):
    1. private InventoryCatalog _catalog;
    2. private readonly List<InventoryItem> _inventoryItems = new List<InventoryItem>();
    3.  
    4. Start()
    5. {
    6. _catalog = GameFoundation.catalogs.inventoryCatalog;
    7. }
    8.  
    9. private void BlahBlah()
    10. {
    11. var definition = _catalog.FindItem(_inventoryItems.definition.key);
    12. ...
    13. slot.itemValue = definition.GetProperty("Value");
    14. }
     
    Last edited: Sep 9, 2020
  6. erika_d

    erika_d

    Unity Technologies

    Joined:
    Jan 20, 2016
    Posts:
    400
    Hi @Shaky6bones

    It looks like you're trying to access the mutable property from the InventoryItemDefinition (found in the catalog). You'll want to use the actual InventoryItem (the runtime instance) to get the mutable properties.

    Try making the call on _inventoryItems[index of the item you want].GetProperty() and the method should show up.
     
  7. Shaky6bones

    Shaky6bones

    Joined:
    Apr 21, 2016
    Posts:
    4
    Thank you, @erika_d!!!

    I feel like a big dummy now. It makes sense, because the mutable properties are specific to the item instance, whereas the static properties and details are "definitional". I guess I expected them to all be accessed in the same way because they were in the same Inventory Window of the editor.

    Thanks also to @mingz-unity. I appreciate the way you both responded quickly and kindly to my questions.
     
    mingz-unity likes this.
  8. erika_d

    erika_d

    Unity Technologies

    Joined:
    Jan 20, 2016
    Posts:
    400
    No problem, I have a little trouble remembering it as well honestly :D Glad we were able to help!
     
  9. kooymj

    kooymj

    Joined:
    Jul 7, 2017
    Posts:
    1
    Hello, I feel like this could be a follow up question.
    I've followed the latest tutorial to change the mutable data, and now I was hoping to load that changed stat.

    For example, the item gains a level and the mutable variable int 1 is changed to 2 and so forth.

    However, next time I load the game, the mutable data loads to its initial properties (in the ex above, level would still be 1), is there a way to save the changed mutable variable?
     
  10. richj_unity

    richj_unity

    Unity Technologies

    Joined:
    Sep 23, 2019
    Posts:
    36
    Mutable properties can be persisted across sessions if you change your data layer from a MemoryDataLayer to a PersistenceDataLayer, which saves the player data to disk. We don't quite have a tutorial for it, but there is a Data Persistence sample in the Game Foundation page in the Package Manager.
     
    erika_d likes this.
  11. DenariiGames

    DenariiGames

    Joined:
    Dec 29, 2019
    Posts:
    13
    The tutorial needs to be updated:

    item.SetMutalbeProperty("tier", tier);
     
    erika_d likes this.
  12. dasparadoxon

    dasparadoxon

    Joined:
    Aug 16, 2014
    Posts:
    11
    I have the same problem and I have set the DataLayer to Local Persistance. (image attached)

    When I then save the Layer via DataLayer.Save() it saves all the items and the quantity of stackable items correctly, but it seems not to save the the mutable properties. It loads everything correctly, but not the mutable properties.

    Which is a bit troubling for me, cause I want to save the player name and the current day in two items mutable properties.

    (Also, but I will put this in another post as well later, it would be nice if Game Parameters also could have a mutable property, cause saving something like current day or players name in an item has a strange feeling to it.)
     

    Attached Files:

  13. erika_d

    erika_d

    Unity Technologies

    Joined:
    Jan 20, 2016
    Posts:
    400
    Hi @dasparadoxon,

    Thanks for your report of trouble getting mutable properties to persist across saves. I will take a look at this and see if I can duplicate the issue!

    (And thanks also for your request about mutable properties on Game Parameters, I know we've had at least one other developer request that as well. Currently the issue is that we don't have runtime instances for Game Parameters- which is necessary for having properties that are mutable at runtime- but I can see there is definite interest around a feature like this.)
     
    dasparadoxon likes this.
  14. dasparadoxon

    dasparadoxon

    Joined:
    Aug 16, 2014
    Posts:
    11
    Stop right there ! Shame on me ! It works fine ! It was me !

    ( At least I know now where and which format the save file is ( as expected : in windows : \AppData\LocalLow\<company name>\<product name>\ ) and in unencrypted json (as expected), filename : GameFoundationSave )
     
    richj_unity and erika_d like this.
unityunity