What is JSON?

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 พ.ย. 2024

ความคิดเห็น • 184

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  4 ปีที่แล้ว +14

    🌐 Have you found the videos Helpful and Valuable?
    ❤️ Support on Patreon www.patreon.com/unitycodemonkey or get the Game Bundle unitycodemonkey.com/gamebundle.php

  • @metal-rain
    @metal-rain 4 ปีที่แล้ว +51

    I watched this video while in bed, don’t even have Unity open, and it makes sense. Thank you very much! I’m excited to get my game started

    • @lordsumitbhati
      @lordsumitbhati 4 ปีที่แล้ว +7

      Haha same here , I am in bed and watch your comment 🤣

    • @felixgeorgescu2230
      @felixgeorgescu2230 3 ปีที่แล้ว +3

      Me too

    • @albertofeng8149
      @albertofeng8149 ปีที่แล้ว +1

      I have the laptop in bed and i am on the floor!

    • @Rivandu
      @Rivandu ปีที่แล้ว +1

      Yup, me too. Couldn’t sleep, maybe watching this helps me, but so far no luck 😂

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  6 ปีที่แล้ว +54

    *Question*
    How do you use this to save multiple different systems?
    *Possible Answer*
    Each System would have it's SaveObject and a function that returns a JSON string, then you would have a master SaveObject that would contain multiple string fields for storing each system JSON save string.
    You would then save the final JSON from that object into a save file.
    For loading you would load that master SaveObject and then use the stored JSON save strings to load all the other systems.

  • @lukaskarlgerhard
    @lukaskarlgerhard 2 ปีที่แล้ว +1

    The speed in which you typed "GameHandler" was incredible. You bow to no-one sir.

  • @AliveNotDeadmund
    @AliveNotDeadmund 4 ปีที่แล้ว +22

    Dude! This tutorial was awesome! Words cannot express my gratitude for unwrapping a topic that had been driving me crazy so simply and precisely. Thank you!!! :D

  • @upsidegaming7134
    @upsidegaming7134 ปีที่แล้ว +2

    This is the best tutorial I've seen in a long time, thank you! You explained how everything worked really thoroughly yet also simplistically. Thanks for the help!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว +1

      I'm glad you liked the video! Thanks!

  • @SPIKEAdventure
    @SPIKEAdventure 4 ปีที่แล้ว +7

    This is thee JSON video I needed thanks for making this!!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +2

      Awesome! I'm glad you found it helpful!

  • @kingdoom1906
    @kingdoom1906 ปีที่แล้ว +1

    Man you are Genius and best unity teacher thank you 🙏

  • @KalechippsDev
    @KalechippsDev 4 ปีที่แล้ว +2

    Just what I was looking for. Thanks!

  • @vaporalight3670
    @vaporalight3670 5 ปีที่แล้ว +77

    In 5:33, You forgot to put "/" in line 18 before "savefile.json". Oddly, in 5:54, the "/" appears in line 18.

    • @infinitefretboard
      @infinitefretboard 5 ปีที่แล้ว +40

      One of the top 10 plot holes of all time.

    • @saif0316
      @saif0316 3 ปีที่แล้ว +3

      You know this man a highly edited videos to make them seem fast 😂

    • @alotofclouds5706
      @alotofclouds5706 3 ปีที่แล้ว +1

      can we get some pining over here?!

    • @razhel7165
      @razhel7165 2 ปีที่แล้ว +1

      the tutorial has to be in perfect condition buddy xD

    • @BloodBarron115
      @BloodBarron115 10 หลายเดือนก่อน +2

      This comment helped me immensely xD

  • @biggestboss
    @biggestboss 6 ปีที่แล้ว +4

    Thanks, I've been wondering about this subject for a while

  • @Pizzaboy_10
    @Pizzaboy_10 4 ปีที่แล้ว +2

    Super useful, much easier than the binary formatter system that I was initially advised to use. Thanks!

  • @albertofeng8149
    @albertofeng8149 ปีที่แล้ว +1

    HEROE!
    Antes no entendia nada nadita del JSON, ahora que he usado varias apis y vuelvo a buscar tutorial (Este), si lo entiendo muy facil!

    • @facelessanon
      @facelessanon 2 หลายเดือนก่อน

      Hugo "Code Monkey" Cardoso understands your comment, as he is Portuguese himself.

  • @NeoLoveCookie
    @NeoLoveCookie 2 ปีที่แล้ว

    This is the best tutorial I ever seen.

  • @ManasJoshi
    @ManasJoshi 3 ปีที่แล้ว

    You are an absolute god!!! Thank you for this video!!!! You saved me!

  • @davidnikolov1995
    @davidnikolov1995 2 ปีที่แล้ว

    bro that was super useful thanks for the help I really needed it

  • @Quasmok
    @Quasmok 3 ปีที่แล้ว

    Just what I needed, thank you!

  • @vilmaryssalgadovivenes8596
    @vilmaryssalgadovivenes8596 4 ปีที่แล้ว +4

    If you cant see your file generated under your project folder name try to replace Application.dataPath for Application.persistentDataPath. it worked for me. it will looks like: File.WriteAllText(Application.persistentDataPath + "/saveFile.json", json);

  • @MaizeDaniele
    @MaizeDaniele 6 ปีที่แล้ว +15

    Great tutorial! Is JSON + IO better than playerprefs in terms of performance? If I have to save settings, what's the best way? JSON or playerprefs? thanks.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 ปีที่แล้ว +17

      You can use JSON in PlayerPrefs as well, its simply a string.Normally I store game settings with PlayerPrefs (Resolution, Keybindings, etc) and game state with save files.
      Cheers!

  • @jean-michel.houbre
    @jean-michel.houbre 4 ปีที่แล้ว +1

    5.42 : File.WriteAllText (Application.dataPath + "saveFile.json", json);
    5.55 : File.WriteAllText (Application.dataPath + "/saveFile.json", json);
    Good joke :)
    After a few questions about this code that was not working, I was able to finish the video. Jason is a nice, accommodating little guy ...

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      I never know if dataPath ends with a slash or not, seems I always get it wrong heh

    • @jean-michel.houbre
      @jean-michel.houbre 4 ปีที่แล้ว

      @@CodeMonkeyUnity Same on the September video: there are stealth slashes (and even SAVE_FOLDER).
      In any case, I learned a lot of things (in particular to be wary of data coming from outside ^^).
      Thanks, I hadn't really messed with the filesystem ...Great moment of solitude ...

  • @yudanaim6849
    @yudanaim6849 3 ปีที่แล้ว

    One of your best videos

  • @kingreinhold9905
    @kingreinhold9905 4 ปีที่แล้ว +1

    You're such a great teacher!!!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      Thanks! I'm glad you found the videos useful!

  • @HaniSharif
    @HaniSharif 2 ปีที่แล้ว

    This was a well made tutorial. Thank you

  • @redbeardjunior
    @redbeardjunior 5 ปีที่แล้ว +2

    I just found thiss and it's some good info thank you I understand it a little better!

  • @harperrhett
    @harperrhett 4 ปีที่แล้ว

    Awesome video, json files turn out to be great for storing item information

  • @RobertGercia
    @RobertGercia 2 ปีที่แล้ว

    Clean and neat tutorial. Thanks and god bless you!!

  • @TKEnvironments
    @TKEnvironments 5 ปีที่แล้ว +2

    Excellent tutorial, very helpful!!

  • @eliy5550
    @eliy5550 3 ปีที่แล้ว

    Thank you so much man.. I will achieve my game dev dreams thanks to people like you.

  • @lime_68
    @lime_68 2 ปีที่แล้ว

    Awesome tutorial, I am new to this

  • @emad-dev
    @emad-dev 6 ปีที่แล้ว +3

    Amazing tutorial.

  • @batuhanartan
    @batuhanartan 4 ปีที่แล้ว

    Very clear explanation, great video ! :)

  • @mardeeferil6468
    @mardeeferil6468 4 ปีที่แล้ว +1

    playerprefs much easy but i want to practice this concepts for cache purposes thanks

  • @wesleycoomans1433
    @wesleycoomans1433 4 ปีที่แล้ว

    Thanks for quick and awesome tut easy to follow and awesome in practice!
    I will use this for my twitch plays (game)

  • @kasunlee7489
    @kasunlee7489 3 ปีที่แล้ว

    Cool. Quick and to the point. Thanks.

  • @ramiq1988
    @ramiq1988 3 ปีที่แล้ว

    Thank you!..Awsome.. the best explanation ever

  • @thepolandman2447
    @thepolandman2447 3 ปีที่แล้ว

    How would you securely save data using json? Should you encrypt the string and if so where would you store the key in order for it to be decrypted on load again? Great video btw!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว +2

      strings are just bytes so you can encrypt them with any algorithm you want.
      But if you're making a game, don't bother with trying to encrypt the saves, it's not worth the effort. If it's a multiplayer game, then store everything in the servers.

    • @thepolandman2447
      @thepolandman2447 3 ปีที่แล้ว

      @@CodeMonkeyUnity Ah yeah alright, I guess you're right. Thanks for the reply, I really like your videos!

  • @kingnoah9658
    @kingnoah9658 6 ปีที่แล้ว +6

    Could you make a tutorial on making a save/load system with multiple slots (Slot 1, 2, 3, etc)?

    • @kingnoah9658
      @kingnoah9658 6 ปีที่แล้ว

      In XML or maybe Binary Formatter?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 ปีที่แล้ว +2

      I have several videos coming up regarding a save system so stay tuned for those.
      But just based on this video you can easily expand the PlayerData to add some fields for whatever you wish to store there.
      For an Inventory System you could define your items with an enum and store it easily.
      private enum Item {
      Dagger,
      HealthPotion,
      }
      private class PlayerData { public Item itemSlot1;
      public Item itemSlot2;
      }

  • @noob70762ify
    @noob70762ify 6 ปีที่แล้ว +2

    thank you very much, for this great tutorial

  • @ravanin
    @ravanin 6 ปีที่แล้ว +2

    3: questions Do you plan to delve deeper into this? What about serializers like odin? When is better to use sqlite?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 ปีที่แล้ว +2

      I'm working on a couple of videos making a Save System, JSON will be used as a simple way to serialize a SaveObject.
      I've not used other serializers, I either use JSON or bytes.
      In a more advanced Save System I'm going to cover how to directly save bytes into a save file and embed a screenshot.
      Cheers!

  • @swannschilling474
    @swannschilling474 3 ปีที่แล้ว

    Thank you so much for this one!!! :)

  • @Diana-qt5gv
    @Diana-qt5gv 5 ปีที่แล้ว +1

    This is an example taken by wikipedia. How can you access the postalCode field, and the type of phoneNumber?
    {
    "firstName": "John",
    "lastName": "Smith",
    "age": 25,
    "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021"
    },
    "phoneNumber": [
    {
    "type": "home",
    "number": "212 555-1234"
    },
    {
    "type": "fax",
    "number": "646 555-4567"
    }
    ],
    "gender": {
    "type": "male"
    }
    }

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 ปีที่แล้ว +3

      Its all about creating objects that match that pattern.
      So in that case it would be this
      public class SaveObject {
      public Address address;
      public class Address {
      public int postalCode;
      }
      }
      Then you would access saveObject.address.postalCode;

  • @Balakademi
    @Balakademi 3 ปีที่แล้ว

    Thank you

  • @dlxinteractive
    @dlxinteractive 4 ปีที่แล้ว +1

    Is it possible to save data to a JSON file and copy then paste the JSON file to another device that has the same project (in a build) to open the JSON file up there (in the build) and have all the data?
    I’m making a level maker for my game and would like a way of copying the JSON file so others can open it up in the build.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      Yup, JSON is just a text file so you can easily copy that around to anywhere you want.

  • @Max-xz8lb
    @Max-xz8lb 5 ปีที่แล้ว

    Code Monkey at around 5:43 you said about seeing if saveFile.json will show up after putting in that code.I tried what you did and that file didn't show up. I'm perplexed by this because to my knowledge changes to the actual project data only appear during runtime or in the actual build of the project and those changes are reversed after the project has stopped running in Unity.
    Seeing the text added to the json file outside of running the project does remind me of an old idea I had. So, If anyone else is confused about this; I created a saveFile.json in my project folder outside of unity and set an absolute path to that file because mine isn't in the base Asset folder and now it works.
    This video is a good start to learning how to use json and I did learn from this.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 ปีที่แล้ว

      The runtime memory data does get wiped as soon as the game shuts down (data stored in variables) but an external file is not automatically deleted.
      Maybe you have some permissions issues. Add a Debug.Log to see where you're saving the file and what response the WriteAllText(); gets.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      @Bebe Agachevo If File.WriteAllText(); doesn't throw an exception then it successfully made the file. So if you don't see any errors then chances are you're not setting the path correctly so it's being saved elsewhere. Try a simple path
      string path = @"c:\MyTest.txt";

    • @vilmaryssalgadovivenes8596
      @vilmaryssalgadovivenes8596 4 ปีที่แล้ว +1

      i fixed it by changing using persistentDataPath. i will looks like: File.WriteAllText(Application.persistentDataPath + "/saveFile.json", json);

  • @diggerfdf
    @diggerfdf 4 ปีที่แล้ว +1

    Nice video! Thanks for showing how to use JsonUtility inside C#.I know that it's possible to use the Json file to "send" the data to some DataBase like SQLite or MongoDb. But how could we lock or cryptograph the data inside Json, so clever and curious player's like us couldn't get inside it, giving ourselves infinity Health, Bullets, God mode, all cards available, etc... ?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +4

      In a singleplayer game you really shouldnt waste time trying to stop cheating, better spend your time making the game better
      In a multiplayer game you should never trust the player for anything so that would require a different design

  • @Akacz47
    @Akacz47 4 ปีที่แล้ว

    Helpful tutorial :)

  • @losfouad2014
    @losfouad2014 3 ปีที่แล้ว

    Hi, Awesome tutorial about JSON Thanks ! i would know if it's possible to save also gameobject ?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      No, you can only store anything that can be converted into text so a reference in memory cannot be stored directly. You can store the type of game object (like if it's a type of weapon or something) or the object position and use that on loading. I handle saving and loading here th-cam.com/video/6uMFEM-napE/w-d-xo.html

  • @adriandeveraaa
    @adriandeveraaa 4 ปีที่แล้ว

    Can you do an item database tutorial? Idk if I should stick with JSON, Regular Script initialization or serialized Scriptable Objects. I need some insight... Ive tried both and Im still unsure which way is better

  • @mysteryman-bg4dt
    @mysteryman-bg4dt 6 ปีที่แล้ว +2

    can you make a quick tutorial showing how to make the basic character controller from the tf2 demoman, including the animations

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 ปีที่แล้ว +1

      It's tough because I'm using my custom animation system.
      I did do some videos on the base of that animation system, check out the videos on how to create and modify a mesh through code, that's the core of the whole system.
      Cheers!

  • @Veevslav1
    @Veevslav1 5 ปีที่แล้ว

    TY, Good tutorial.

  • @dennisgonzales9521
    @dennisgonzales9521 5 ปีที่แล้ว +1

    Awesome as always!!!
    Cheers!

  • @stuart5980
    @stuart5980 2 ปีที่แล้ว

    I'm trying to do this with bolt, what would be the visual scripting equivalent of creating a playerdata class for a json utility node?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      I don't think there's any way to create a new class structure just with Bolt. But you can make a very basic C# file just to define the structure and then use it with Bolt

  • @johnson8216
    @johnson8216 4 ปีที่แล้ว

    can u create a video on how to create json array

  • @brunoseba15
    @brunoseba15 13 วันที่ผ่านมา

    Is possible to do this without creating a class to store the values??, like just having an array of int and pass directly the data of the json

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  12 วันที่ผ่านมา

      JSON stores key-value pairs so it needs a field to know the name of it. So yes you need a class/struct to hold the data, I don't think JsonUtility.ToJson(); works, although I never tried that myself

    • @brunoseba15
      @brunoseba15 11 วันที่ผ่านมา

      @@CodeMonkeyUnity confirmed that not works, i hace tried un that way but ir doesn't understand the strings so give an insanely big value(something like 1211111000).Thanks for the answer!!, just to mention contrats for tour c# course on teachable, i already finished it is really complete

  • @missmuffetmcpe6034
    @missmuffetmcpe6034 3 ปีที่แล้ว

    I liked how you went into detail on how to do it, but I would like some help understanding how it does what it does, I'm just starting to make a practice app, and my friends wanted to make a dating sim. So naturally I have to learn how to make a save and load file system. I just need a little more help. Please and thank you.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว +1

      JSON is a file format, what it does is really just type conversion from whatever type into string and back again.
      Tehcnically the JsonUtility uses Reflection to find the class member fields and uses System.Convert to do all conversions.

  • @Chevifier
    @Chevifier 5 ปีที่แล้ว

    I was trying to figure out how to find parse nested object doing it in reverse (ToJson) help me figure out how it should be formatted. Thanks A Mill

  • @Epsio0
    @Epsio0 3 ปีที่แล้ว

    I'm having trouble with arrays within the JSON object. I've found that JSONUtility isn't so good with handling that, still trying to make this wrapper solution I've found on the forum to work but no luck. Wondering if you have had similar problems with array within a json object

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      What trouble? It works perfectly fine with arrays, just has issues with List and Dictionary

  • @gongjiaji2489
    @gongjiaji2489 6 ปีที่แล้ว +1

    this video helps me a lot , thank u

  • @myelinsheathxd
    @myelinsheathxd 4 ปีที่แล้ว

    thx!

  • @legendaryswordsman2279
    @legendaryswordsman2279 ปีที่แล้ว

    I'm not all that familiar with JSON, however I noticed when it's saved in a file it's all on one line, is there a way to format it so it takes up multiple lines and is more human readable?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      If you load that file onto a browser it will be parsed and it will be easy to edit.
      I don't think Unity's JsonUtility has a PrettyPrint function

  • @yangli7230
    @yangli7230 3 ปีที่แล้ว +1

    JSON is easy to make save and loading, but it's really easy to read which also makes it easy to modify, so a more better way of doing this is binary. Because their binary thier really hard to read which also make them very hard to modify.

  • @gameplaystories4130
    @gameplaystories4130 4 หลายเดือนก่อน

    Thanks for u! And for that comment too

  • @haachamachama7
    @haachamachama7 2 ปีที่แล้ว

    Hey, i know this is a fairly old video, i wonder if you have any newer ones... I wonder if you could answer a question for me... How does one go about assigning a super complex JSON to an object without making a bunch of classes? For example, I have one I'm working on with a client, and the JSON being downloaded via an API get request he has me working with is like...
    "data": {
    "mainMenuConfig": {
    "booksConfig": {
    "content": [
    {
    "title": "",
    "category_items": [
    So, the only way I can figure out how to assign this is make an object for data, for mainMenuConfig, for booksConfig, for content, and for category_items, so 5 objects in total(most pointlessly holding another object lol, even the "title" variable isn't being used)?! I wonder, what is the point of these nested objects? lol, why does mainMenuConfig not just contain the "content"? But, that's besides the point, would you happen to know an easier way to assign these values without making a bunch of objects? FYI i need the Data because it actually contains another object further down(i just didnt want to make this comment gigantic lol).
    But it took me like 2 hours to get all the values assigning... i wonder if there's a more efficient way to do this? Besides creating 5 useless classes to hold all this info lol, this isn't the first time I've come across overly complex JSON files containing seemingly empty, useless objects that just hold another object lol. I tried using JsonNode as well, but that just makes it so you have to assign each value manually and it makes the script look kinda sloppy...

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +1

      Visual Studio has an option for "Edit > Paste Special > Paste JSON as Classes" which automatically creates the classes for you
      Alternatively you can look into the dynamic C# keyword, although I haven't used it myself docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/using-type-dynamic
      Questions about the structure of the JSON really should be asked whoever made that JSON, only that person knows, maybe they have a good reason for those empty containers, or maybe it's just bad code.

    • @haachamachama7
      @haachamachama7 2 ปีที่แล้ว

      @@CodeMonkeyUnity Ohh, I didn't know of that paste JSON as Classes option. I once did a job for a client where i was just making like 10+ different classes out of JSONs, I was just pasting them one by one, erasing the values and turning them into variables, it took forever, that would've saved me a ton of time haha
      Thanks for the help! I'll read that doc too to see if i can use that.

  • @JacobS-rh7tb
    @JacobS-rh7tb 4 ปีที่แล้ว

    Very good tutorial, thank you. I saw your reply on a comment below saying that you wouldn't consider JSON as a "safe" way to store data. It is very easy to crack/access it for android apps for instance (i.e. quick editing it to hack the game). I know you wouldn't store anything really worthy on it but I'm just wondering if there's a better/safer way to keep players from cheating/bugging and keep things a little less exposed. I can't see how json would be better than making a proper encoded save system and using the cloud/database system on the platform you are using (firebase/steamcloud/google services/etc). Thank you!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +2

      The only way is to keep your secure data on a server and only give the player limited read access. If the player is in possession of the data then you should assume they can manipulate it.
      But for the most part I would say don't bother with people cheating in your games unless you're making something multiplayer.

  • @BeerfootBandit
    @BeerfootBandit 5 ปีที่แล้ว

    Performance wise, would it be good to use json to save every 10 minutes or so with a bunch of info like in a city builder?
    And can i save/load json with Jobs if performance is an issue?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 ปีที่แล้ว +1

      Sure a autosave every 10 minutes should work just fine, worst case scenario is your game hangs for a second but if its only once every 10 minutes it's unlikely anyone will be bothered by it.
      I wouldn't bother jobifying the save code, it's not an issue unless for some reason you needed to save every second.

    • @BeerfootBandit
      @BeerfootBandit 5 ปีที่แล้ว

      Thanks for the answer. Think I'll use json and playerprefs now

  • @BloodBarron115
    @BloodBarron115 10 หลายเดือนก่อน

    don't like necro threading but i tried using this and the file is not creating. i have a debug that shows string json is set to the data i expect but file.writealltext isn't writing to the file. This vid is 5 years old but did they change anything about how this needs to work since then or am i just missing something?
    *edit*
    Found the issue reading a different comment. There was a missing \ before saveFile.json but it was there after coming back from saving the file. works now!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  10 หลายเดือนก่อน

      heh yeah this has happened to me several times, always add a Debug.Log to verify you are saving exactly where you think you are to make sure you're not forgetting a /

  • @TheGrimmy
    @TheGrimmy ปีที่แล้ว

    despite making the PlayerData class when I save PlayerData playerData = new PlayerData(); it sais playerData does not exist in the current context.
    It's like; I know that's why I'm making it :S
    Before this, is it wise to create that variable in Start along with the save and load code? Shouldn't they be their own functions that you can call in your game?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      Sounds like you instead wrote new playerData(); and the type is named PlayerData not playerData, remember that everything is case sensitive.
      As to when you do that, yes in a proper game you would hook the load logic to some kind of UI button click and not on Start unitycodemonkey.com/video.php?v=6uMFEM-napE

    • @TheGrimmy
      @TheGrimmy ปีที่แล้ว

      @@CodeMonkeyUnity Thank you for your help :D Yes, will definitely save that one for monday. Cheers :D have a good weekend

  • @aledbarreto
    @aledbarreto 3 ปีที่แล้ว

    But does this method support nested object as well?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      Yes, as long as those types are Serializable

  • @satriair04
    @satriair04 3 ปีที่แล้ว

    What if someone forging our json file manually and accidently delete some string & value. It could give some kind of error in the game, isn't ? Do we need some try-catch in our code or something or maybe set default value in that private classes ?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      Yes JSON is easily editable so you need to validate your data

    • @satriair04
      @satriair04 3 ปีที่แล้ว

      @@CodeMonkeyUnity Oke, Thank you sir !

  • @curiousnewt9928
    @curiousnewt9928 4 ปีที่แล้ว

    What would be the process for saving for example a list of custom classes, that each contain list with additional custom class? What happens for me is, it only creates json with reference ID, which I actually don't need. I need the data from the classes in those lists, but I'm unable to get/save them.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      You need to either use Structs instead of Classes, or manage references yourself with some kind of unique id system

  • @abdulmaliqjinad1244
    @abdulmaliqjinad1244 2 ปีที่แล้ว

    How do you save the json data to an online storage using the "www" class?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      That depends on whatever you have running on the server. That class is just for doing a HTTP request unitycodemonkey.com/video.php?v=Gk0-amfn5DM
      What you do on the server depends on what you have in the server, could be a simple PHP script recording the incoming input onto a database

  • @BrandonBrady97484
    @BrandonBrady97484 2 ปีที่แล้ว

    How do you get this to work with webgl

  • @sneddengonsalves9320
    @sneddengonsalves9320 2 ปีที่แล้ว

    working with enum and list dont seem to work, I did convert on my enum into int, just doesn't work as expected

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      That is working as expected, enums are really int's with fancy names, so the serializer is doing exactly as intended. If you convert it back you will see the enum value again.
      Lists also work, perhaps you're trying to save a list with a custom data type? If so you need to make sure that custom data type has the attribute [Serializable]

  • @jacobbell3745
    @jacobbell3745 3 ปีที่แล้ว

    How do I make a list of playerdatas serializable? It always says there isn't anything in the list when I run it

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      You need to add the attribute System.Serializable to your custom classes th-cam.com/video/6uMFEM-napE/w-d-xo.html

  • @varan9412
    @varan9412 4 ปีที่แล้ว

    why it's so easy?? Thanks

  • @llYuki0okami
    @llYuki0okami 2 ปีที่แล้ว

    For days I have been trying to do such a simple thing as to write in the form of text on the screen the content loaded from the text file. All that works for me is writing this text to the console via debug.
    YT tutorials do not work because they do not take into account Text Mesh Pro.
    When I try to get help on websites for unity users, discord or forum, I only get "advices" to check my code thoroughly and fix it myself. I really have no more strength.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      TextMesh and TextMeshPro works pretty much exactly the same, you just set the "text" field with the text you want, that's it. For reading the file you just use File.ReadAllText();

    • @llYuki0okami
      @llYuki0okami 2 ปีที่แล้ว

      @@CodeMonkeyUnity no its not the same, you need to use using TMPro; and use TextMeshProUGUI thing, but when i try its breaking a script i dont know how to make it work, maybe by change text from the file to string variable and use this variable in visual script to change meshpro text but i try this for days and cant do it.

  • @ДенисСкрягин
    @ДенисСкрягин 6 ปีที่แล้ว +2

    Если присмотреться, то этот способ очень хорош для сохранения больших объектов, не разбивая на составляющие, как я это делал используя PP. Урок мне понравился..

  • @jaredlandetta5136
    @jaredlandetta5136 3 ปีที่แล้ว

    Is there a way to duplicate the json files? I want to create a json file everytime I start the game. This only updates de json file if it changes. How do I do that?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      It's just a normal file, so you can just do File.Copy();

  • @ApexArtistX
    @ApexArtistX 5 ปีที่แล้ว

    please make tutorial on built in json parsing specific response key

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 ปีที่แล้ว

      What do you mean parsing speecific response key? You mean contacting an API? That's going to depend on what API you are dealing with.
      Usually you don't have to manually parse anything, as long as the field name and type match.

    • @ApexArtistX
      @ApexArtistX 5 ปีที่แล้ว

      @@CodeMonkeyUnity yes that tutorial. Without using their party library. Most tutorials are only about saving and loading file. Need Jason rest API receiving method

  • @louischvs9395
    @louischvs9395 3 ปีที่แล้ว

    How to work with array? like int [*, *, *]?

  • @ApexArtistX
    @ApexArtistX 5 ปีที่แล้ว

    can u do it from another Endpoint server json

  • @SubhanshuThapa
    @SubhanshuThapa 6 ปีที่แล้ว

    How to Parse the JSON to get an array of image URLs.? So that I would be able to assign those images to their respective UI Image Elements.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 ปีที่แล้ว +1

      Not sure what you mean, a image URL is just a string so just create an object with a string value and parse the json onto it.

    • @SubhanshuThapa
      @SubhanshuThapa 6 ปีที่แล้ว

      @@CodeMonkeyUnity Thank You for your response. I have parsed the JSON and stored the string URLs value into 3 different string variables Link1, Link2, and Link3. After that, when I am Passing those string values using start coroutine as its actual parameters (for example : StartCoroutine(DownloadImage(Link1,Link2,Link3)); to download images using WWW then It is giving me an error message " *uriformatexception: uri scheme must start with a letter and must consist of one of alphabet, digits, '+', '-' or '.' character* ". I probed Unity Answers and Asked question about my problem but didn't get response from anyone. I wonder why it is giving me this error even though the string contains valid URL starting with *https* ://.
      I apologize for this lengthy reply but I want to get rid of aforementioned problem.

  • @gianmarcopane2806
    @gianmarcopane2806 5 ปีที่แล้ว

    Great tutorial =D

  • @NathoSteveo
    @NathoSteveo 3 ปีที่แล้ว

    legendary

  • @tareqmahmud3902
    @tareqmahmud3902 3 ปีที่แล้ว

    Is it possible to create objects using json in unity?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      What objets? JSON is just data, it can represent whatever you want

    • @tareqmahmud3902
      @tareqmahmud3902 3 ปีที่แล้ว

      @@CodeMonkeyUnity Suppose, I have a json file like this,
      [
      {object 1 : [91,23,65]},
      {object 2 : [44,23,85]},
      {object 3 : [27,63,55]},
      {object 4 : [25,33,25]},
      {object 5 : [52,93,65]},
      ]
      >>
      So I was asking that can I create objects with given x,y,z co-ordinate using that JSON file?

    • @Inarilein
      @Inarilein 2 ปีที่แล้ว

      @@tareqmahmud3902 You can create objects with the saved data, if you use them, but JSON cannot create objects on itself. It's just a method to save data like string, boolean, integer and anything you can convert into a text.

    • @tareqmahmud3902
      @tareqmahmud3902 2 ปีที่แล้ว

      @@Inarilein yes, exactly what I was looking for! But how?

  • @jemrules835
    @jemrules835 4 ปีที่แล้ว

    my json file has spaces so how do I put that in my program

  • @gelis07
    @gelis07 4 ปีที่แล้ว

    if i turn off the computer can i load my last save?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      You need to save data to something persistent th-cam.com/video/6uMFEM-napE/w-d-xo.html

    • @gelis07
      @gelis07 4 ปีที่แล้ว

      @@CodeMonkeyUnity thank you!

  • @James31006
    @James31006 2 ปีที่แล้ว

    What's a Vector

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      It's a Vector, something with X, Y and maybe Z en.wikipedia.org/wiki/Vector_(mathematics_and_physics)

  • @longnguyen427
    @longnguyen427 4 ปีที่แล้ว

    If I want to save a static variable in json file, how can I do ?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      Copy it into whatever object you're converting into json, check out these videos th-cam.com/play/PLzDRvYVwl53vRrMuPBkNNZUmnl1jCHcHs.html
      Just add a field in the SaveObject

    • @longnguyen427
      @longnguyen427 4 ปีที่แล้ว

      WOW thank you so much

  • @StephenAllenGames
    @StephenAllenGames 4 ปีที่แล้ว

    Nicey nice!

  • @yesveryprofesionalnameyes6055
    @yesveryprofesionalnameyes6055 5 ปีที่แล้ว +2

    Wait, isnt it super easy to hack json data if it is so easy to read?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 ปีที่แล้ว +3

      Yes JSON is intended to be easy to read and write so it's not suitable if you're concerned about security.
      But unless your game is online or extremely specific I wouldn't worry about people hacking their own single player save games.

    • @aunabbas8582
      @aunabbas8582 5 ปีที่แล้ว

      Use Binary Serialization instead, a secure way for saving and loading data.

  • @illia1732
    @illia1732 2 ปีที่แล้ว

    What if my class has a Sprite inside? I can't serialize it)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      You need to reference it in some way, maybe store the sprite's name, maybe a GUID. Alternatively you can serialize an image with base64, I actually covered how to include a screenshot in your save file here unitycodemonkey.com/video.php?v=dqySkMFieHE

  • @jordangaona5240
    @jordangaona5240 6 ปีที่แล้ว +2

    It works on android o IOS?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 ปีที่แล้ว +2

      Yes you can use JsonUtility while building for mobile.

  • @reggiesmemestash5773
    @reggiesmemestash5773 4 ปีที่แล้ว +1

    Lol who is jason and why is he in my computer

  • @notrue4u
    @notrue4u 2 ปีที่แล้ว

    i mean the data can be easily manipulated by anyone who knows how to work with JSON?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      JSON is not meant for security, it's not encryption, just a nice data format that is easy to handle and recognized in so many languages/APIs

    • @notrue4u
      @notrue4u 2 ปีที่แล้ว

      @@CodeMonkeyUnity ohh thanks for the information!

  • @PVlibras
    @PVlibras 2 ปีที่แล้ว

    ❤🧡💛💚💙💜

  • @nickolasbrown2260
    @nickolasbrown2260 ปีที่แล้ว

    I have a better one. Who is json ?

  • @SairentoHiruGuy
    @SairentoHiruGuy 3 ปีที่แล้ว

    JESUS CHRIST!!! HOW DA FCKING USE THIS FILE!!!! I HAVE .JSON....AND I DONT KNOW HOW USE IT!!! WHY YOU DONT TELL THIS???

  • @pachitko4390
    @pachitko4390 6 ปีที่แล้ว +1

    XML is better!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 ปีที่แล้ว +2

      Well it depends on what you're doing but JSON is much cleaner and much more supported pretty much everywhere.
      I wouldn't recommend XML unless you absolutely have to.

  • @kjuliana6012
    @kjuliana6012 2 ปีที่แล้ว

    Thank you so much for this amazing tutorial