Search Unity

Official Getting Started with Game Foundation Preview

Discussion in 'Game Foundation' started by mingz-unity, Sep 23, 2019.

  1. mingz-unity

    mingz-unity

    Unity Technologies

    Joined:
    Oct 12, 2017
    Posts:
    63
    What is Game Foundation

    Game Foundation provides you with pre-built common game systems (such as inventory, currency, stats) that are flexible and fully extensible, so that developers can focus more on building the unique gameplay instead of reinventing wheels on the most common / essential systems.


    Installing the Preview Package

    Game Foundation Preview is released as a preview package in Package Manager. Minimum required Unity version for the package is 2018.3.

    Please refer to the Installing pre-requisites guide for a step by side guide on how to install it.

    We currently support these Build Target platforms: iOS, Android, Mac, Windows


    Game Foundation Developer Guides

    Please head over to the package documentation page for quick start guide as well as detailed step-by-step tutorials on using each system we provide:

    https://docs.unity3d.com/Packages/com.unity.game.foundation@0.6/manual/index.html
     
    Lurking-Ninja likes this.
  2. Yay! QQ: when the announcement was made it was told that it will be a mobile package. I took a quick look (without downloading, because I can't do that right now) and I haven't found any reference to any hard mobile prerequisite. Does this mean that the GF will be a general purpose package for any kind of application rather than only for mobiles?
    I'll play around with this a bit later.
     
  3. JayR

    JayR

    Joined:
    Aug 2, 2016
    Posts:
    84
    Game Foundation is not inherently limited to mobile and should also be fine on desktop platforms. There may be limitations on some features on more-restrictive platforms (WebGL and consoles.)
     
    Lurking-Ninja likes this.
  4. MadanyNO

    MadanyNO

    Joined:
    Apr 18, 2016
    Posts:
    16
    i was wondering if i make a custom Detail Definition, can i require that it will need another Detail on the item? like u do with some components?
    like i make Equipment Definition and i want it to require the stat definition. is there a way to go about that? dont think i saw one in the ducs

    edit: if there is explantion on what needed to be done to add new Detail Definition it could be helpfull too since my new Detail Definition doesnt show up to be add on the Game item details
     
    Last edited: Oct 10, 2019
  5. mingz-unity

    mingz-unity

    Unity Technologies

    Joined:
    Oct 12, 2017
    Posts:
    63
    Thanks for reaching out @MadanyNO. Some very good questions here.

    Custom Detail: it's not entirely impossible to do, but quite difficult since we haven't well documented the API interface for you to create your custom details. We do have plan to better support this option for developers in the near future, including better documentation / explanation that you mentioned, so stay tuned.

    Also in the meanwhile, if you can share with us your use case / what you want to do with the Custom Details, it could also help us take that into consideration when designing it.

    For your question on required Detail: yes that's something we're currently looking into as well. We haven't made final plans yet on how that can be supported, but we do understand it can be useful sometime.
     
  6. MadanyNO

    MadanyNO

    Joined:
    Apr 18, 2016
    Posts:
    16
    tnx for answering me @mingz-unity i really see a lot of potential in GF as some one that tried to self create system like that for myself.

    about what i am trying to do is something like this:

    create a detail definition for Equipment, which would hold the type of it and the rarity of it. at list for now.
    and i want it to require the Stat detail so i can give bonus stats when equipped.

    For example i will create a game item, name it "One Handed Sword" and add the Equipment Detail to it.
    in the detail i will give it the type "One-Handed Weapon" and the rarity of "Common".
    And because i put the stat detail as required, it would add the stat detail or worn me i need to add it myself.

    i kind of expect the code for the Equipment detail i described to be something like this:

    Code (CSharp):
    1. [RequireDetail(typeof(StatDetailDefinition))]
    2. public class EquipmentDetailDefinition : BaseDetailDefinition
    3. {
    4.  
    5.     public EquipmentType type;
    6.     public RarityType rarity;
    7.    
    8.     public override string DisplayName()
    9.     {
    10.         return "Equipment Detail";
    11.     }
    12. }
    to use the RequireDetail just like i use RequireComponent r RequireComponentData.

    Also, i created a class like that(without the RequireDetail) in my project, but when i try to Add the detail, i only see the details that come with the package.
    Is there a need to do something more when creating new Detail? Because i watched the presentation about GF in Youtube from Unity Copenhagen and it seems like a thing i should be able to do.
     
  7. mingz-unity

    mingz-unity

    Unity Technologies

    Joined:
    Oct 12, 2017
    Posts:
    63
    Thanks for the additional information @MadanyNO. The scenario you described makes a lot of sense.

    Indeed it requires more steps than just that to get your Custom Details supported right now, but better support will be provided in the near future so that developers can be relatively easy to add their own Custom Detail.

    One additional follow-up question from the user story you provided above. I noticed you're using 'type' as an attribute in your Custom Detail to model the different types of Equipment. Is there any particular reason you prefer to do it this way, than say using the Definition on the left side (e.g. creating a new definition for each type of equipments, assuming if you can also use Inheritance to link to the base Equipment)?

    We try to provide a flexible system so there's no 'wrong' way to do it, but currently we do see more cases where developers would use Definition for that purpose, while using Detail for holding specific attribute for a concept.
     
  8. MadanyNO

    MadanyNO

    Joined:
    Apr 18, 2016
    Posts:
    16
    not sure i got how you suggested to handle the equipment type...
    did u mean to make a game item of one hand sword, and then when i want to create a new sword i create a new inventory item to inherited detail from my one hand sword, then it simple, i didnt think about that XD
    i did see the why u did the sword item in the tutorial, but i guess it didnt strike me as what i was looking to do

    and the EquipmentType is more of an enum, to use as a label, and in my opinion it is easier to create the equipment like that. Because say i made an sword item with all the stats, info, and now i think that this equipment is more of a lance then a sword so i want to change it to lance, so i only need to change the label, and its a lance, and i wont need to change the inherited from sword to lance.
    so my equipment detail is more of something i would like to have each item to itself and not something he inherited.
    at list that what i was going for.

    i am mainly playing around with GF to test it and see how i feel with it compered to the old made up system i created for myself a year ago as a project for my degree ^^" my system worked but it had lots cons.... i guess i still think on creating items as i created in my system ^^"
    now that i think about that, i can even use the category as a label instead of my equipment type.

    on another note, i was wondering about something:

    can i use the categories i created to sort or get only specif items in my inventory that belong to specific category?
    for example if i have a tab window in my in-game inventory that i want to present only potion that were categorized as "potion" items, can i use the categories to get only the items that categorized as "potion"?
     
  9. erika_d

    erika_d

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

    Thanks for trying out Game Foundation and sharing with us your use cases!

    As far as your question about looking up groups of items based on their category, yes, that is a thing you can do! It looks like a bug in our documentation that it's not showing up in the scripting reference, but here is a list of method signatures that you can call from Inventories:
    - public InventoryItem[] GetItemsByCategory(string categoryId)
    - public void GetItemsByCategory(string categoryId, List<InventoryItem> items)
    - public InventoryItem[] GetItemsByCategory(int categoryHash)
    - public void GetItemsByCategory(int categoryHash, List<InventoryItem> items)
    - public InventoryItem[] GetItemsByCategory(CategoryDefinition category)
    - public void GetItemsByCategory(CategoryDefinition category, List<InventoryItem> items)

    For the one's that return void, they will add the list of items that fit the category into the List<InventoryItem> that you pass in.

    And just as an added note of clarification, I saw you mentioned further up about creating custom details because you saw it in the presentation from Unite, I just wanted to call out that parts of that presentation was a demonstration of plans we have for the future of Game Foundation, so certain things, like the custom details, aren't supported yet, but we plan to in the future.

    Hope that helps!
     
    mingz-unity likes this.
  10. MadanyNO

    MadanyNO

    Joined:
    Apr 18, 2016
    Posts:
    16
    Hi @erika_d

    Tnx for the list of method!
    and about the custom details tnx for clearing up that it isnt yet supported, i will wait for the update with those.

    tnx for answering my question till now, i will keep playing with Game Foundation to test it and wait for update on custom details for more use cases :)
     
    erika_d likes this.
  11. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Hi
    I just tried Game Foundation and now wondering how can I implement such game with it:
    The game is about managing houses. Each house has its own settings and a list of rooms. Each room also has its own settings and characteristics (simply to say 'Details'). And Room also contains a list of items (such as bed, microwave, table etc)

    So my idea is next:
    Create 2 game items and details:
    1. House (id: house) with HouseDetail
    2. Room (id: room) with RoomDetail
    3. RoomItem (id: roomItem) with RoomItemDetail

    Then in inventory populate items:
    - House_1 (id: house_1, reference def: house)
    - House_2 (id: house_2, reference def: house)
    - House_1_Room_1(id: house_1_Room_1, reference def: room)
    - House_1_Room_2(id: house_1_Room_2, reference def: room)
    - House_1_Room_3(id: house_1_Room_3, reference def: room)
    - House_2_Room_1(id: house_2_Room_1, reference def: room)
    - and so on...
    - Table(id: table, reference def: roomItem)
    - and other room items

    Problems and questions:
    1. it will become a mess if I will have more than 5 houses in the game. Yes, I can use categories, but anyway... Maybe I should make it differently?

    2. Can I create new Houses and Rooms at runtime? So not predefined houses but random one?

    3. How can I link items to room or vice verse? (store items' ids in RoomDetail?)


    It is just an example. In a racing game, there will be garages with cars with some upgrade modules that can be installed.
     
    mingz-unity and erika_d like this.
  12. MadanyNO

    MadanyNO

    Joined:
    Apr 18, 2016
    Posts:
    16

    about your 2nd question sadly creating new items in run time is blocked for now in Game foundation, u still can create a script that will randomly create those rooms but it needs to be done before you enter play mode you can create new items by using InventoryItemDefinition.Create(string id, string displayName).
    if u want u can have an editor window that will randomly create a new room when u press on a button or create 100 random rooms on a different button.

    about the way to go about the game u described, i would probably go about it something like this:

    create all the base items like table and such first.
    then go to inventory and create 2 new inventories:
    1. roomInventory
    2. houseInventory
    make sure they are not auto created

    Then use a script to create a InventoryItemDefintion for a room with a custom Detail for RoomInfo that will hold a room id.
    Then for each room created, create an inventory for the room using InventoryManager.CreatInventory(roomInventory, string name). for the name use the room id from from the room detail. or "room_xx" where xx is the id.
    then add randomize items to the room inventory you created.

    make houses the same way as rooms. and i think that will work for u.

    for now, u can only do this from scripts outside play mode, but it is do able with editor windows and such. and after u created all those rooms and houses u dont need to create them again.

    at list that how i will go about it.

    if u want random every time u start a new game, that will need to create them in game mode which isnt possible right now.
    hoped i helped some what :)


    btw @erika_d is there a reason creating at playmode was blocked? i think it limits a lot of Game Foundation abilities to open option for users to use it.
     
    MUGIK and erika_d like this.
  13. erika_d

    erika_d

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

    Thanks for your question and use case. I think my answer of how to go about setting up something like this ended up being very similar to @MadanyNO's but I'm including it below since I've got some added details about setting it up in the existing editor windows and using stats instead of custom details.

    A few callouts to start out with:
    - At the moment, there isn't an ability to create custom details, although that is intended to be included down the line, as shown in our Unite video. You can create your own stats, which are (currently) numerical (float or int) pieces of data and can be attached to items as a statDetail. So if your characteristics are numerical, you could create them as Stats and attach them that way.
    - Also reference definitions are currently supposed to be a 1:1 mapping between game items and inventory items. There's currently a bug in the UI that allows a game item to get set as a reference definition for multiple inventory items if it's the first time it's being connected, but that's not currently the intended use pattern. This is something we're evaluating though, as we've definitely seen and experienced ourselves the use case for applying one template to multiple items.
    - I also think the easiest solution to your question would be if inventories could also be items to be added to another inventory. That's not currently possible, but something that we have seen use cases for, and have added it to our list of possible things to consider in the future.

    Ok those being said, I think this is how I would go about it:

    - In the Inventory tab of the Inventory Editor Window I would create
    1) A House inventory definition
    2) Room inventory definitions for each type of room you want (i.e. Living Room, Kitchen, Bedroom, etc). For the room inventories I would make the id numerical only (i.e. 1, 2, 3). The numerical only id will be kind of a pain when coding it, so I would add in your code an enum or dictionary that maps the numerical ids to a readable/rememberable id.

    NOTE: For both house and room inventories, you could create just one of each type and leave the default items empty and fill them with items on the fly during runtime, or you could create multiple of each with each configuration of default items that you want in them (i.e. House1 which would have a bedroom and a kitchen, House2 which would have a bedroom, a kitchen, and a living room, and Kitchen1 with stove and table and Kitchen2 with stove, table, microwave, oven)

    - In the Inventory Item tab I would create:
    1) The roomItems that you want to be able to put in the room inventories (i.e. table, light, bed, microwave). You could use categories to identify for each roomItem what rooms they are eligible to be added to, which might be useful for random generation later.
    2) A room inventory item for each room inventory you created. I would then attach to each room inventory item an inventoryId stat detail, and assign the numerical id for the inventory that the inventory item maps to in the stat detail.

    For each of the relevant items you could add additional stat details for any of the settings and characteristics you wanted to associate with them (assuming they can be defined numerically) instead of creating custom details for them at this time.

    This set up allows you to create groupings of rooms within houses, and roomitems within rooms, and different configurations of each grouping.

    In your runtime code then, you could instantiate as many House Inventories as you want from the House InventoryDefinition you set up in the editor. If you created multiple House InventoryDefinitions then they would already have the rooms set up for each, if not, then you could add the rooms to each inventory (Either intentionally or through a randomization algorithm). And same with the rooms. You can instantiate as many copies of a kitchen room inventory and inventory item, adding the kitchen inventoryItem to the house inventory and adding roomItems to the kitchen inventory, if that makes sense.

    @MadanyNO, to answer your question, you are correct that you can't create or edit new definitions at runtime for now (although you can instantiate and edit as many runtime items/inventories as you want). The reason we prevent that is because there were some difficulties with serializing and saving new definitions on the fly and edits to existing ones. We're aware though that having the ability to make changes like that at runtime would be helpful and it's an issue we're conscious of trying to solve.

    Hope that all helps and is clear! Thanks again for both of your input, questions and answers!
     
  14. Alexproxy

    Alexproxy

    Joined:
    Oct 13, 2019
    Posts:
    1
    Hello good morning, I recently used the game's foundation and I have a small problem, I try to save the statistics of the game items of the game but it doesn't save them, just save if they are from an inventory
     
  15. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Could you provide a bit more information, perhaps share the code that you are using? Are you referring to data persistence for the stats?
     
  16. EthenCortez

    EthenCortez

    Joined:
    Jan 16, 2020
    Posts:
    1
    I think a more efficient solution is to save the inventory as a table of strings, that way you only actually save items that the player owns. (It also means you don’t have to manually add boolean table entries in the script)
     
  17. DeadlyArtist

    DeadlyArtist

    Joined:
    Oct 19, 2018
    Posts:
    9
    Is this compatible with dots and netcode? (just came across this package and was wondering)
     
  18. ajayrawat222

    ajayrawat222

    Joined:
    May 2, 2020
    Posts:
    1
    Hi,
    I have been using this package in my game but facing problems in saving my or the state of the game foundation. Can anyone provide the possible way to store it using persistence data? I want to implement the Save and Load feature.
    Please help me with this.
     
  19. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you share the code that you are using, perhaps share a bit more about your Save/Load requirements?
     
    Last edited: May 4, 2020
  20. erika_d

    erika_d

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

    I'll add to Jeff's response that there are sample scenes that can be downloaded from the package manager (minimum version Unity 2019.2) which show how to save and load from the data layer. Sample 06 Data Persistence demonstrates saving and loading locally using a LocalPersistence data layer and sample 09 ChilliConnect demos server persistence using a ChilliConnect data layer. You can also read more about the data layers here. Hope that helps!
     
    mingz-unity likes this.
  21. ben-rasooli

    ben-rasooli

    Joined:
    May 1, 2014
    Posts:
    40
    Can someone please explain what problem the Game Foundation is trying to solve (in a very high abstract conceptual level)? I already read and watched almost all the available docs and tutorials. The reason I'm asking is that I have a feeling that this system can be used for many things, but I just can't figure it out yet. I'm trying to find out how much of my gameplay logic can be handled by this system. For instance, I'm working on a game where the players can spend their coins to get some power-ups before entering a level. Leaving the level will vanish the power-ups. The coins are persistent from one game session to another, but the power-ups are only for that game session. So, what puzzling me is that should I convert the power-ups into an InventoryItem? Is this what the Game Foundation designed for?
     
  22. mingz-unity

    mingz-unity

    Unity Technologies

    Joined:
    Oct 12, 2017
    Posts:
    63
    Hi @ben-rasooli - for the scenario you described, indeed InventoryItem might be the best fit, since you need to persist the state of how many power-ups the user owns as the result of coin spending.

    For your question on Game Parameter, its main use case is static configuration for your game, which also offers remote configuration capability (through CC adapter), and we will also provide a/b test ability for Game Foundation in the near future as well. For Game Foundation itself we will also leverage Game Parameter to offer configurability for the systems we provide, e.g. whether to turn on/off certain features, which can also be overridden remotely by an a/b test service such as DeltaDNA. Overall Game Parameter is designed to be flexible, and indeed as you say can be used for many things. But for your scenario of persisting gameplay states from runtime, it won't be a good fit, because fundamentally it's a static configuration system and won't store runtime state changes.

    Hope this helps.
     
    ben-rasooli and erika_d like this.
  23. ben-rasooli

    ben-rasooli

    Joined:
    May 1, 2014
    Posts:
    40
    How would I tie the Game Systems to a user account. Is there any build-in solution in GF to work with ChilliConnect user account system as demonstrated here?
     
    Last edited: Sep 25, 2020
  24. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Hi @ben-rasooli,

    You can find an example of how to use ChilliConnect to work with Game Foundation in the Sample Scenes that can be downloaded from Package Manager (Sample 09_ChilliConnect). In that sample it shows how to create a player and link it to Game Foundation. Let me know if that answers the question!
     
    ben-rasooli likes this.
  25. antoine-agthe_unity

    antoine-agthe_unity

    Unity Technologies

    Joined:
    Jun 6, 2019
    Posts:
    7
    Hello @ben-rasooli ,

    To build on what @erika_d said, we don't handle the authentication inside Game Foundation because it depends on the data layer you use:
    • if you use the
      MemoryDataLayer
      , it is because you want to get the raw data of Game Foundation in order to save it your way. No authentication required.
    • if you use the
      PersistentDataLayer
      , you want to save the Game Foundation state, locally, or in the Cloud.
      For this one, you can provide your own implementation of
      IDataPersistence
      , so you can push into the Cloud if you wish (1).
    • if you use the ChilliConnect Data Layer available in the Sample of Game Foundation, you probably you a more advanced communication with a server.
      Then you need the initialize it with a
      ChilliConnectSdk
      instance (2).
    For the situation (1) and (2), you can see that the authentication depends on the service you use.
    Exposing the authentication though the Game Foundation API could make it difficult to maintain, as you might choose to implement your own Data Layer, or your own
    IDataPersistence
    , which could require authentication to services we don't know.

    To focus on ChilliConnect: this service provides a couple of different ways to authenticate:
    Exposing the same authentication possibilities in the Game Foundation API would force (or at least invite) any Data Layer to support those possibilities, and no others.
    Maybe you have your own Cloud Save service, with you own authentication system.
    Then you would be blocked.

    I hope it helps you understand the context.
    Otherwise, do not hesitate to ask!
     
    mitaywalle, ben-rasooli and erika_d like this.