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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Loading contents, information, scriptableObjects from text file?!

Discussion in 'Getting Started' started by NowKnown, Sep 20, 2016.

  1. NowKnown

    NowKnown

    Joined:
    Jul 23, 2015
    Posts:
    5
    Hello everyone,
    I want to know, if the current way (or the way I'm planning) to load information is the right and optimal method.

    What I'm going to create:
    I want to create a game, where many information about different objects store in text files. At the start, all those information get loaded into the game and create different objects. In the finished project, there should also be an editor in the game to create your own objects.

    Implementation:
    There are different text files in several folders and each of them contains different informations (syntax) (such as weapon-files, enemy-files, tile-map-level-files, etc.) The GameController loads a folder which contains all the files is sub folders.

    Example:
    There is a simple weapon like a sword. The text file may look like this:
    image:"/img/sword.png"
    name:"master sword"
    damage:5
    range:2

    Maybe use a other way?
    I'm looking for the best way to load informatino to create/fill objects on runtime. What's about the scriptableObject, is this what I'm looking for?

    I just want to know this, before starting creating the base of my game.

    please excuse my bad english skills.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    I do this sort of thing in High Frontier using GRFON. It's certainly not the only way, but it works well for us.
     
  3. NowKnown

    NowKnown

    Joined:
    Jul 23, 2015
    Posts:
    5
    Thanks for the answer! GRFON looks good, I already worked with XML so this is also very usefull. But would it also be possible with scriptableObject?
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    I'm not sure whether you can get scriptableObject to save its data in any human-readable form. And even if you can, I'd stay away from it because (like most standard C# serialization) it's likely to be fragile, i.e., to break if you change the interface of your code.

    But then again, maybe not — Unity objects in the editor aren't especially fragile, except for enum properties (which are stored by value rather than by name). So, it's certainly worth digging into further if that's how you want to go.
     
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,137
    From the documentation for JSON serializing:
    https://docs.unity3d.com/Manual/JSONSerialization.html
     
    JoeStrout likes this.