How to SAVE and LOAD XML Files DATA in Unity

  Рет қаралды 11,672

Beaver Joe

Beaver Joe

Күн бұрын

Пікірлер: 17
@VBFilms
@VBFilms 4 жыл бұрын
I've been watching these xml-saving tutorials for a while and I must say this is the best one of them.
@beaverjoe9171
@beaverjoe9171 4 жыл бұрын
VBFilms thx for your high likes!!!!
@rulyhyperion8277
@rulyhyperion8277 3 жыл бұрын
This is the first save/load thing that worked for me, and it's quick and easy to use. Thank you very much
@gregspot9538
@gregspot9538 4 жыл бұрын
Muchas gracias amigo, sinceramente el mejor video para guardar y leer archivo XML. THXXX SO MUCH!!!!
@PhazonBlaxor
@PhazonBlaxor 2 жыл бұрын
There is no need to use tags and to write every single variable individually (that's really confusing and waste of time), just make the data class you want to save serializable, then use XmlSerializer to write the whole class in one go to a XML-file. To load, you simply reverse the process. Like so: public void Save() { if (!Directory.Exists(Application.persistentDataPath + folderName)) //If folder does not exist, create it { Directory.CreateDirectory(Application.persistentDataPath + folderName); Debug.Log("Created data path"); } XmlSerializer serializer = new XmlSerializer(typeof(Save)); //Set the Save class to be serialized FileStream stream = new FileStream(Application.persistentDataPath + folderName + fileName + fileExtension, FileMode.Create); //Setting FileMode to Create to write the file serializer.Serialize(stream, _save); //_save is a reference to the serializable Save class, just make the reference however you wish to do it. stream.Close(); //Always remember to close the stream! } public void Load() { if(File.Exists(Application.persistentDataPath + folderName + fileName + fileExtension)) //We only load if the save file actually exists { XmlSerializer serializer = new XmlSerializer(typeof(Save)); //We do the same process as with saving FileStream stream = new FileStream(Application.persistentDataPath + folderName + fileName + fileExtension, FileMode.Open); //Set FileMode to Open to access the data file _save = (Save)serializer.Deserialize(stream); //Deserialize the file and cast it as Save data (or whatever your data class is called) stream.Close(); //Once again, you must close the stream or you lock the access. } else { Debug.LogWarning("Save File Not Found!"); } } That's all you need to do! Just modify the variables in the Save class directly in-game, so you don't need duplicates and to remember tens of tags. Simple, eh? Note: You need to be using System.Xml.Serialization to access the serialization classes.
@PassiveSnack
@PassiveSnack 4 жыл бұрын
Great video, just what I needed! My appreciation is immeasurable! Subscribed.
@beaverjoe9171
@beaverjoe9171 4 жыл бұрын
PassiveSnack thx so much. If u try to use methods save and load data on webGL, only one method can work. I remember is xml. But I am stilling finding any solutions on unity forum. There are the same issues someone faced on forum. Btw. Happy New Year!!🎈🎊
@elladitch9698
@elladitch9698 5 жыл бұрын
OMG this is just what I want. Thx man, u really help a lot!
@beaverjoe9171
@beaverjoe9171 5 жыл бұрын
Thanks! 😁
@nikitazuev3331
@nikitazuev3331 5 жыл бұрын
You are the best. Thanks for tutorial. But one question, how to add at the TOP?
@beaverjoe9171
@beaverjoe9171 5 жыл бұрын
Thanks for your likes and comments. Happy ThanksGiving! 🎈 💫The XML declaration typically appears as the first line in an XML document. The XML declaration is not required. 🥬 If you want to add, You can open your XML file and add it to the top I think. (You can try it but I do not promise. I remember when I learned HTML, I did not use this line but all works 🍄)
@nikitazuev3331
@nikitazuev3331 5 жыл бұрын
@@beaverjoe9171 Unfortunately without this line my native language (cyrillic) dont reading. Ok. One more question, how to assign an attributes? XmlNodeList LoadedEnemys = XmlDoc.GetElementsByTagName("Enemys"); No problem, but how to use: XmlDoc.Attributes["Value1"].Value; ???? Thanks.
@VBFilms
@VBFilms 4 жыл бұрын
I just moved my unity project to another computer and now I'm getting an error "Input string was not in correct format". Even though it is. It seems Unity can't parse my float numbers. If I make the values whole numbers it works, but the problem comes from the floats. This worked on my other computer.
@yvesevrard2421
@yvesevrard2421 4 жыл бұрын
Thanks man, good videos
@beaverjoe9171
@beaverjoe9171 4 жыл бұрын
Thx for your likes. There is much more to come in the next year!
@G00LDENGoosse
@G00LDENGoosse 3 жыл бұрын
Thanks helped alot
@McdoApp-h3p
@McdoApp-h3p 9 ай бұрын
Jian Yang?
How to Access XML Data in Unity - Game Development Tutorial
19:09
Turbo Makes Games
Рет қаралды 10 М.
Walking on LEGO Be Like... #shorts #mingweirocks
00:41
mingweirocks
Рет қаралды 4,9 МЛН
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 10 МЛН
Sigma baby, you've conquered soap! 😲😮‍💨 LeoNata family #shorts
00:37
How to make a Save & Load System in Unity
26:56
Shaped by Rain Studios
Рет қаралды 199 М.
XML Tutorial for Beginners | What is XML | Learn XML
6:39
Clever Techie
Рет қаралды 395 М.
[UNITY3D] Работа с Asset Bundles
10:33
ANDROIDHELPER [UNITY3D and more]
Рет қаралды 32 М.
SAVE & LOAD SYSTEM in Unity
18:20
Brackeys
Рет қаралды 1,1 МЛН