Storing Data (Objects & Lists) with JSON - Unity Tutorial 2021

Поделиться
HTML-код
  • Опубликовано: 10 ноя 2024

Комментарии • 90

  • @xyhc-cnc
    @xyhc-cnc 3 года назад +19

    This is so well done! This video is easily one of the most helpful, informative, and well-explained Unity saving tutorials I could find. The quality of the video deserves at least a couple hundred thousand views!
    You make amazing stuffs and deserve so much recognition. Thank you for sharing your knowledge!

    • @VelvaryGames
      @VelvaryGames  3 года назад +2

      Oh thank you, that's so great to read :) I'm really glad you like the content

  • @pawegorka8589
    @pawegorka8589 5 месяцев назад

    11:30 i was sure that there will be a mistake in my code, but nah,
    this tutorial is amazing, im glad i found you

  • @josepereira6968
    @josepereira6968 3 года назад +1

    This is one of the best videos about a subject in Unity, the quality is very good, keep going !!!
    Thank u for this video !

  • @b3armonk
    @b3armonk Год назад

    Thank you so much Michelle for putting this together. I have to watch it over and over to understand it.

  • @thyroid99
    @thyroid99 10 месяцев назад

    Great! Thanks for keeping it generic and walking us through the steps!

  • @NicholasAYam
    @NicholasAYam 3 года назад

    Thanks, Velvary! You saved me heaps of times searching for the clearest explanation for JSON savings~~~~ Highly recommended for beginners to JSON!

  • @YadroGames
    @YadroGames 2 года назад

    Even the Brackeys textbooks didn’t help me, but it all looks good in this video, thank you. I subscribed

  • @chrischains9947
    @chrischains9947 Год назад

    Excellent. The last part about writing/reading single objects was especially a nice touch :D

  • @lilbocheap139
    @lilbocheap139 2 года назад

    Incredibly valuable information. I've been searching for how to do this for so long but there's very few clear, through, well put together videos like this. Thank you so much for taking this time.

  • @jasons387
    @jasons387 2 года назад

    you are simply amazing!!! my headache is now gone. Thank you for being you and doing what you do

  • @sidhuarya
    @sidhuarya 3 года назад +2

    That was a really good tutorial! Everything was really well explained and to the point. Keep up the great work! :)

  • @ALEXWARDRAGON
    @ALEXWARDRAGON 2 года назад

    Even after a year this video helps me a lot. Thanks :D

  • @Metalsorow
    @Metalsorow 2 года назад

    Thank you for this tutorial with great detail. Very informative and non dependent on other deeper knowledge.

  • @cagricibuk
    @cagricibuk 3 года назад

    Explanation is better than others nice job 👍

  • @andreychumakov8952
    @andreychumakov8952 2 года назад

    This is just what i was searching for! Thank you!

  • @simonak9699
    @simonak9699 Год назад

    Amazing tutorial. You have a new subscriber, and I look forward to watching your other videos.
    Thank you so very much for the time and effort put into this.

  • @fabioburkard
    @fabioburkard 3 года назад +1

    Just what I needed, but was lazy to look for =)

  • @nguyenchidi8148
    @nguyenchidi8148 Год назад

    Realy realy grateful and appreciative for you

  • @WickedLizardWizard
    @WickedLizardWizard 3 года назад

    Wonderful explanation of everything that goes into this, thank you!

  • @TheShadowrunner81
    @TheShadowrunner81 2 года назад +1

    hi, i tried this example but when thw file is written the content is missing, it just writes {"Items":[{}]} i debugged the Scripts and i see that the values of the input field is correctly passed to the filehandler as an array. but the wrapper seems to ignore that somehow

  • @Avogeorgee
    @Avogeorgee 2 года назад

    Thank you so much, this is exactly what I needed :)

  • @estogaza5827
    @estogaza5827 2 года назад

    Well...This video saved me hours and hours of pain.

  • @piotrgora5715
    @piotrgora5715 2 года назад

    You Made My day Thank you and also you have lovely voice

  • @juanpedraw4245
    @juanpedraw4245 2 года назад +1

    So how would you delete items from the list???

  • @NoorFatima-sq2go
    @NoorFatima-sq2go 2 года назад

    bestt bestt bestt explanation

  • @anumey1
    @anumey1 2 года назад

    Absolutely well made video.

  • @AboutLeon
    @AboutLeon 2 месяца назад

    How to access the data from the file and implement it into unity? Hopefully you have a continuation video of this? Will look through your videos, this one was good for writing to a file, but there is no accessing the data into unity.

    • @jayvlyn
      @jayvlyn Месяц назад +1

      That is what reading the file is for. You read the data back into unity using the file name.

  • @demaciaviceotter2347
    @demaciaviceotter2347 2 года назад

    Helped me a lot, good job

  • @gamedev_navneet
    @gamedev_navneet 2 года назад

    Great tutorial. Impressive effort. It is helpful 👍.

  • @htavli
    @htavli Год назад

    This is great! Thank you!

  • @Raxlash
    @Raxlash 3 года назад +1

    How can I overwrite information?

  • @anchalindavis5569
    @anchalindavis5569 2 года назад

    Super Sis...love it so much

  • @relentingVids
    @relentingVids 3 года назад

    This is fantastic! Thank you!

  • @ryanb2633
    @ryanb2633 2 года назад

    Now that I've saved and have my list, where do I go about Loading and grabbing information from specific items in list?

  • @apemant
    @apemant 3 года назад

    Thank you, very easy to understand!

  • @pacoantonio1573
    @pacoantonio1573 2 года назад

    Great tutorial!

  • @harsh3771
    @harsh3771 9 месяцев назад

    I need a help, I just want to read from json , whats the easiest way

  • @dansletten3681
    @dansletten3681 Год назад

    WOW Thanks for sharing awsome :)

  • @alexxxchange
    @alexxxchange 2 года назад

    so helpful thank you!

  • @Smartoyunda
    @Smartoyunda 2 года назад

    How to override to spesific saved data (each object has unique ID of List) ?

  • @adityashanbhag5044
    @adityashanbhag5044 2 года назад

    Thank you for the tutorial, neatly explained. I have few doubts, it would be of great help if you could solve them
    1. I am trying to store an image of type sprite in json and it is getting converted to instance id, how can i convert it back or is there a different way to store sprites in json?
    2. Am trying to Read the data stored(availableList = FileHandler.ReadFromJSON(filename);) in a start method of another script by iterating over the loop and printing the data, but nothing gets printed, is there any other method to read the data?

    • @adityashanbhag5044
      @adityashanbhag5044 2 года назад

      I was wrong about question 1, instace id is created for every json file(Did not know that), but still no srpite, tried converting it to bytes[], still empty is being written in bytes[]

    • @VelvaryGames
      @VelvaryGames  2 года назад +1

      @@adityashanbhag5044 so you really want to save the content of the image? I assume you have a special use case for this, otherwise I would recommend to just save a reference. Unfortunately I haven't tried this, but looks like the information is not serializable for the JSON package. That would mean you have to write your own serialize to somehow convert the image in a string format.
      And for 2: There should be two methods, a simple "ReadFromJson" and the list one "ReadListFromJson". Use the second one, that should return the list. Otherwise you data might not get parsed correctly which could also lead to empty responses.

    • @adityashanbhag5044
      @adityashanbhag5044 2 года назад

      @@VelvaryGames Hi Appreciate your quick response, i am working on the 1st point to convert. On 2nd point, i managed to retrieve the list of data, but the problem am having is, everytime i run the game, the data is being overwritten, My old data is gettng earsed and new one is replacing it. i tried the following code, but did not work, could you suggest something?
      public static void WriteFile(string path, string content)
      {
      FileStream filestream;
      string fileName = Application.persistentDataPath + "/" + "new.json";
      if (File.Exists(fileName))
      {
      filestream = new FileStream(path, FileMode.Open);
      List list = ReadFromJSON(fileName);
      string old = JsonHelper.ToJson(list.ToArray());
      content += old;
      }
      else
      {
      filestream = new FileStream(path, FileMode.Create);
      }
      using (StreamWriter writer = new StreamWriter(filestream))
      {
      writer.Write(content);
      }
      }

    • @VelvaryGames
      @VelvaryGames  2 года назад +1

      @@adityashanbhag5044 Mh, ReadFromJson should always return the type you defined (here Character) but never a list, so I assumed you modified the FileHandler script, which makes it not possible for me to help. If you want you can post your whole script in my discord server and I can take a look what's the problem. Otherwise your data should not be overwriten, because a correctly working loading part handles this. There is no need for manually concatinating json strings.

  • @alexandrebasso6923
    @alexandrebasso6923 2 года назад

    I LOVE YOU ! THANKS.

  • @wowff24kgnw
    @wowff24kgnw 3 года назад

    감사합니다 좋은 강의였습니다.

  • @muireachgriogalach483
    @muireachgriogalach483 2 года назад

    If you want to delete from json, you can store your entry to another script
    GameObject InsRoad = Instantiate(road, hit.transform.position, road.transform.rotation);
    RoadEntry x = new RoadEntry(road.name, gridTile.x, gridTile.y);
    entries.Add(x);
    InsRoad.GetComponent().entry = x;
    then delete it with:
    entries.Remove(hit.collider.GetComponent().entry);

  • @oii432
    @oii432 Год назад

    Thank you its work fine

  • @PunjiThePlayer
    @PunjiThePlayer Год назад

    Thank you very much

  • @mustafasalema2121
    @mustafasalema2121 2 года назад

    I want save two data in one file but its overwritten the old data How i can do it please help , I use Append but it store previous data also i don't want the previous data , please help me out

  • @handlevognhandlevognsen3128
    @handlevognhandlevognsen3128 24 дня назад

    Ty so much

  • @danielbianco6300
    @danielbianco6300 2 года назад

    It would make it way easier if you exported things as unity package so that there's no issue with using different versions of unity for it. Otherwise amazing tutorial

  • @isyrafsyahmi8775
    @isyrafsyahmi8775 2 года назад

    Hi,
    I have a question regarding the randomScores.json . I'm using macOS, how do I find my randsomScores.json even though I already typed the file name on unity? I have no idea on this..

    • @isyrafsyahmi8775
      @isyrafsyahmi8775 2 года назад

      please help me anyone.

    • @VelvaryGames
      @VelvaryGames  2 года назад

      That's why there is this "Debug.Log()" statement which should print your location. So if you did not remove it you should see your path in the console being logged

  • @-lunte.
    @-lunte. Год назад

    so good! omg

  • @ryanb2633
    @ryanb2633 2 года назад

    When I save, it is only saving the InstanceID. Any thoughts?

    • @muireachgriogalach483
      @muireachgriogalach483 2 года назад +1

      you can't save gameobjects at there

    • @ryanb2633
      @ryanb2633 2 года назад

      @@muireachgriogalach483 gotcha yeah I realized that wasn’t going to work. When I flipped back to her original way, I still get it though but my code looks like hers. Think it is my class that I’m doing it wrong?

    • @ryanb2633
      @ryanb2633 2 года назад

      I got it worked out, actually. Thanks again

    • @muireachgriogalach483
      @muireachgriogalach483 2 года назад

      @@ryanb2633 you can think it like minecraft, there is item ids at minecraft, you can save a item id to json(your ItemEntry) then create a item database and at that database your prefab and item's id should be same, then while loading your game compare your database with your item id of json data and you will find correct id and can create same prefab at your game also you should store position color etc. as you know

    • @ryanb2633
      @ryanb2633 2 года назад

      @@muireachgriogalach483 that’s a good way to look at it! Is the item I’d just the position in the list/array or is that something to set too?

  • @FrankUnderwood2023
    @FrankUnderwood2023 3 года назад

    best tutorial. Well explained every step, for noob like its very helpful! Sub/like!!!

  • @kyleburdeos9681
    @kyleburdeos9681 2 года назад

    This works on android?

  • @cgraider
    @cgraider 2 года назад

    :|
    Cannot implicitly convert type 'inputEntry' to 'System.Collections.Generic.List'

    • @VelvaryGames
      @VelvaryGames  2 года назад

      Please compare your code to the code from my github. It looks like you just made a mistake there, but without seeing your code I cant help you

    • @francescodarrigo3038
      @francescodarrigo3038 2 года назад

      Did you figure out what was causing this? Just ran into the same error.

    • @cgraider
      @cgraider 2 года назад

      @@francescodarrigo3038 it was 7 month ago i cant remember sorry

    • @mmdiniz
      @mmdiniz Год назад +1

      The reason for that is to give an example in this statement: List rawList = new List(); it is trying to instantiate List to the variable rawList, which means it doesn't have any value assigned to it. Therefore, the missing value is assigned to it using rawList.Add(); just to provide an example. Excuse any mistakes in my grammar :)

  • @laniakeadev.2271
    @laniakeadev.2271 2 года назад

    ArgumentException: JSON must represent an object type.

  • @PESCADORSHOES
    @PESCADORSHOES 2 года назад

    It's you Amel?

  • @DeadRabbitCanDance
    @DeadRabbitCanDance 5 месяцев назад

    For save Vector3 need create serializable version this class
    [System.Serializable]
    public class SerializedVector3
    {
    public float x;
    public float y;
    public float z;
    public SerializedVector3(float x, float y, float z)
    {
    this.x = x;
    this.y = y;
    this.z = z;
    }
    public SerializedVector3(Vector3 vector3)
    {
    x = vector3.x;
    y = vector3.y;
    z = vector3.z;
    }
    }
    public static class Vector3Extensions
    {
    public static Vector3 ToVector3(this SerializedVector3 serializedVector3)
    {
    return new Vector3(serializedVector3.x, serializedVector3.y, serializedVector3.z);
    }
    public static SerializedVector3 FromVector3(this Vector3 vector3)
    {
    return new SerializedVector3(vector3);
    }
    }

  • @Korn1holio
    @Korn1holio 2 года назад

    Damn. I can't believe JSONUtility still doesn't support Arrays. What kind of witchcraft is this?

  • @LION303200
    @LION303200 Год назад

    confusing !!!

  • @loghmannanwayboukani9945
    @loghmannanwayboukani9945 Год назад

    Excellent. Thank you so much.