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!
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.
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.
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
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.
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?
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[]
@@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.
@@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); } }
@@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.
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..
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
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
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);
@@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 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
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 :)
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
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); } }
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!
Oh thank you, that's so great to read :) I'm really glad you like the content
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
Great! Thanks for keeping it generic and walking us through the steps!
Thank you so much Michelle for putting this together. I have to watch it over and over to understand it.
This is one of the best videos about a subject in Unity, the quality is very good, keep going !!!
Thank u for this video !
Thank you :)
Even the Brackeys textbooks didn’t help me, but it all looks good in this video, thank you. I subscribed
Thanks, Velvary! You saved me heaps of times searching for the clearest explanation for JSON savings~~~~ Highly recommended for beginners to JSON!
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.
ehh classica
Excellent. The last part about writing/reading single objects was especially a nice touch :D
you are simply amazing!!! my headache is now gone. Thank you for being you and doing what you do
Even after a year this video helps me a lot. Thanks :D
Thank you for this tutorial with great detail. Very informative and non dependent on other deeper knowledge.
That was a really good tutorial! Everything was really well explained and to the point. Keep up the great work! :)
Thank you :)
This is just what i was searching for! Thank you!
Explanation is better than others nice job 👍
Just what I needed, but was lazy to look for =)
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.
Wonderful explanation of everything that goes into this, thank you!
bestt bestt bestt explanation
Thank you so much, this is exactly what I needed :)
You Made My day Thank you and also you have lovely voice
Realy realy grateful and appreciative for you
Helped me a lot, good job
Absolutely well made video.
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
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.
That is what reading the file is for. You read the data back into unity using the file name.
Great tutorial. Impressive effort. It is helpful 👍.
Great tutorial!
So how would you delete items from the list???
Super Sis...love it so much
This is fantastic! Thank you!
This is great! Thank you!
Well...This video saved me hours and hours of pain.
WOW Thanks for sharing awsome :)
It still comes out as {"Items":[{"instanceID":-39626},{"instanceID":-39660}]} instead of a readable file
Did I miss something?
I need a help, I just want to read from json , whats the easiest way
Thank you, very easy to understand!
Thank you, that's nice to hear
Now that I've saved and have my list, where do I go about Loading and grabbing information from specific items in list?
How can I overwrite information?
How to override to spesific saved data (each object has unique ID of List) ?
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?
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[]
@@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.
@@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);
}
}
@@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.
I LOVE YOU ! THANKS.
감사합니다 좋은 강의였습니다.
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..
please help me anyone.
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
so helpful thank you!
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
so good! omg
Thank you very much
Thank you its work fine
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);
otherwise storing with index is pain on the back for me
When I save, it is only saving the InstanceID. Any thoughts?
you can't save gameobjects at there
@@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?
I got it worked out, actually. Thanks again
@@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
@@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?
Ty so much
:|
Cannot implicitly convert type 'inputEntry' to 'System.Collections.Generic.List'
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
Did you figure out what was causing this? Just ran into the same error.
@@francescodarrigo3038 it was 7 month ago i cant remember sorry
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 :)
This works on android?
best tutorial. Well explained every step, for noob like its very helpful! Sub/like!!!
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
It's you Amel?
ArgumentException: JSON must represent an object type.
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);
}
}
Damn. I can't believe JSONUtility still doesn't support Arrays. What kind of witchcraft is this?
confusing !!!
Excellent. Thank you so much.