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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

firebase database vs scriptable objects unity

Discussion in 'Scripting' started by doronhn, Aug 3, 2018.

  1. doronhn

    doronhn

    Joined:
    Jul 27, 2018
    Posts:
    27
    hey,

    i was wondering what is the different between - Firebase database vs Scriptable objects.
    someone use both? why pick one on another?
     
  2. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    765
    Firebase is an online database, the games would have to be connected to the network to access it. All games would be connected to the same database, if one of them changes data, they will all see it. It is appropriate for data that can change over time such as leader boards, player stats.

    Scriptable Objects are essentially prefabs without gameobjects. All the data in a scriptable object is produced by you (the developer) and will end up on the binary. They store configuration for your game. It is appropriate for things that never change such as colors of buttons, sword stats, enemies stats, song list, etc. Data in scriptable objects does not go over the network. They work even if your game is offline.
     
    TonyLi likes this.
  3. doronhn

    doronhn

    Joined:
    Jul 27, 2018
    Posts:
    27
    so if i have 300 levels- what is the best way to store them? on Firebase or Scriptable objects?
    if i understood you correctly, if i will save them on Firebase i will have the possibility to add level without the need to upgrade version.

    am i right?
     
  4. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    765
    That is correct, if you add the levels in firebase you would be able to add new levels without upgrade. If that is your requirement, yes, firebase would be appropriate.

    You could also do a combination: Have most of your levels in scriptable objects so it is faster and works offline, while loading extra levels from firebase for DLC levels.

    If you are going to store your levels in firebase, try to make them small. Downloading huge things from firebase will quickly run into your free bandwidth quota, especially if your game becomes popular. It could also be slow to download on mobile data plans.
     
  5. doronhn

    doronhn

    Joined:
    Jul 27, 2018
    Posts:
    27
    got it.
    i think i will store my levels in local and upgrade from time to time.

    can you explain to me how to do so? you have any tutorial?
     
  6. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    What are you attempting to accomplish?

    Comparing Firebase and ScriptableObjects isn't even a apple's and oranges thing, it's a house and airplanes comparison... they're barely related except in the most mundane manner.

    What are these "levels"? What is the act of "adding a level"?

    Most levels in unity are created as 'Scenes'... which has nothing to do with ScriptableObject or Firebase. Do you plan to create your own data container or something that you convert into scenes through some process?

    Also, there are plenty other options to both ScriptableObject and Firebase .
     
  7. doronhn

    doronhn

    Joined:
    Jul 27, 2018
    Posts:
    27
    so please tell me :)
    level is basically a size of the board, starting point , point to complete the level and some other "flat" properties.
    all the boards are created in the same way, so i dont need multi scene.

    am i wrong?
     
  8. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    OK, so by level you mean a simple data container that describes the information you need to build a level. And that data container is 'flat'.

    So what I would do is now define that data container as a simple serializable struct/class:

    (note I don't know the data types of the values you're considering here)
    Code (csharp):
    1.  
    2. [System.Serializable]
    3. public class LevelData
    4. {
    5.     public int Size;
    6.     public Vector3 Start;
    7.     public Vector3 Goal;
    8.     public string Other;
    9.     public int Other2;
    10.     public float Other3;
    11. }
    12.  
    I'd forego ScriptableObject all together since that's more of a editor time only structure. But rather instead allow a ScriptableObject be an optional data store for it:

    Code (csharp):
    1.  
    2. public class LevelAsset : ScriptableObject
    3. {
    4.      public LevelData Level;
    5. }
    6.  
    And now that LevelData is serializable as a simple data structure, that could be stored anywhere you'd like. As a json file, as a ScriptableObject, inside 'Firebase' (which returns data as json), inside a SQLite database, in an xml file, in an ini file, in whatever thing you want.
     
    goldbug and hopeful like this.