Simple Saving and Loading with JSON to a File (Unity Save System Tutorial for Beginners)

  Рет қаралды 146,907

Code Monkey

Code Monkey

Күн бұрын

🌍 Get my Complete Courses! ✅ unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
Series Playlist: • Simple Saving and Load...
Grab the Project files and Utilities at unitycodemonkey.com/video.php...
Let's learn Saving and Loading in Unity by using JSON as our file format and saving it into a File.
If you have any questions post them in the comments and I'll do my best to answer them.
See you next time!
Grab the game bundle at unitycodemonkey.com/gameBundl...
Get the Code Monkey Utilities at unitycodemonkey.com/utils.php
#unity3d #tutorial #unity2d
--------------------------------------------------------------------
Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.
I've been developing games for several years with 7 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
You can see my games at www.endlessloopstudios.com
--------------------------------------------------------------------
- Website: unitycodemonkey.com/
- Twitter: / unitycodemonkey
- Facebook: / unitycodemonkey

Пікірлер: 260
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
🌐 Have you found the videos Helpful and Valuable? ❤️ Support on Patreon www.patreon.com/unitycodemonkey or get the Game Bundle unitycodemonkey.com/gamebundle.php
@stevanrose7090
@stevanrose7090 Жыл бұрын
Dude I love you so don’t get me wrong but I think this video would be a little better if you start new projects or child like examples for us noobs 🤣
@Lord_Of_The_Beer
@Lord_Of_The_Beer Жыл бұрын
@@stevanrose7090 he has lots of other videos in which he starts from a blank project. Some of his videos are even full classes. You should check them out, all the ones I've watched have been super helpful.
@GlobusTheGreat
@GlobusTheGreat 2 жыл бұрын
I have a computer science degree but I'm not ashamed to say that I still enjoy and benefit from watching your coding videos as they are so very practical and stress the importance of clean and reusable code!
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Thanks! Learning is a never-ending journey so always keep learning!
@GlobusTheGreat
@GlobusTheGreat 2 жыл бұрын
@@CodeMonkeyUnity Amen! And thank you for helping so many in that continuous process
@ggre55
@ggre55 2 жыл бұрын
i totally forgot about this i cant believe how easy it is, thank u. i think i need to watch more videos about this topic
@petermarsh4578
@petermarsh4578 3 жыл бұрын
Your tutorials are so effective, well explained and, most importantly, straight to the point! No annoying waffle! I've studied programming for 5 or so years now and have just picked up Unity, and you are helping me so much! Keep it up :)
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
Thanks! I'm glad you found them useful!
@relentingVids
@relentingVids 2 жыл бұрын
Thank you for this! Also if anyone wants the save file to not have the "_" on the first save time but have it if the save exists. For example it will save the first file as "save.txt" then any save after will be "save_1.txt" , "save_2.txt" , "save_3.txt" and so on Just use the following code as the Save function. public static void Save(string saveString) { string theFirstSavePath = Path.Combine(Application.dataPath, "Save Folder", "save.txt"); string theFollowingSavesPath = Path.Combine(Application.dataPath, "Save Folder", "save_" + saveNumber + ".txt")); int saveNumber = 1; if (File.Exists(theFirstSavePath) || File.Exists(theFollowingSavesPath) { while (theFollowingSavesPath) { saveNumber++; } File.WriteAllText(theFollowingSavesPath), saveString); } else { File.WriteAllText(theFirstSavePath), saveString); } }
@alexandrugd5218
@alexandrugd5218 3 жыл бұрын
Very nice tutorial, I'm glad you made one on this topic
@shivamprajapati6839
@shivamprajapati6839 3 жыл бұрын
You are legend man! Thanks a lot...
@tatboy9157
@tatboy9157 Жыл бұрын
Learned a lot ,tks :)
@user-kq4gt6jz3r
@user-kq4gt6jz3r 5 жыл бұрын
Keep doing this.!
@GameDevGeeks
@GameDevGeeks 3 жыл бұрын
Saving files???
@322ss
@322ss 5 жыл бұрын
Thanks for the video once again - off topic question; are the keyboard sounds picked up by mic or from capture software? If they are not synthetic sounds then may I ask what keyboard / switches :) ?
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
The sounds are from the keyboard. It's a very old but awesome keyboard, I've had it for over 10 years and it still works perfect. It's a Samsung SWT1000. I've wanted to try making the jump to a Mechanical Keyboard but everytime I go look at whats available I get confused with the dozens of types of switches and just end up keeping this one. Cheers!
@tomershmaya8852
@tomershmaya8852 4 жыл бұрын
@@CodeMonkeyUnity if you want a good Mechanical one I highly recommend Marvo KG935. But it's going to make a lot of noise in the background :)
@eclipset.9683
@eclipset.9683 2 жыл бұрын
I like the Gamdias Hermes Ultimate. It's got brown switches, which are ideal for long periods of sustained typing. Somewhat louder, but comfortable. Plus the keyboard has excellent gizmos and gadgets built in for anything you might need. On the fly macro recording, extra keys all over. (I use the thumb keys below space for frequently used F keys). Also has a special rubber piece that makes the keys actuate more quickly. Keyboard is ideal for both gaming, writing, and programming. But I'm sure everyone has their personal opinion of what's best. The Gamdias doesn't have RGB, only red, (other Gamdias keyboards do, though), it's pretty big, but it's got the USB and mic/audio pass through. It's lasted me somewhere around 6~8 years.
@Sillymonkeies
@Sillymonkeies 2 жыл бұрын
Thank you!
@bigbangpegasusmaster
@bigbangpegasusmaster 3 жыл бұрын
it's giving me an "Object reference not set to instance of an object" whenever I try to use any of the IUnit methods (and yes I do have something set for Unit)
@manuelillanes1635
@manuelillanes1635 4 жыл бұрын
Hi, I don't know why but it never create a file, it can create a folder but it is always empty. I'm compiling for android, i don't know if that is what is causing the problems.
@chinyonglim7624
@chinyonglim7624 5 жыл бұрын
If I used json file as database to store something like player information(like player's name, level), and publish as apk 1.0. After a moment, I had updated and added certain new information(now it have player's name, level, stat and win/lose records) to the same json file and publish as new apk 1.1, Will the previous player information (name and level) lost and replaced by new and clean json file? Or how should we remain the old data while we updating json files?
@tomershmaya8852
@tomershmaya8852 4 жыл бұрын
If you use the File.WriteAllText method as in the video it will overwrite the previous JSON . Anyway, JSON is not "append-able", so while you can use another method like File.AppendAllText to add (and not overwrite) information, it will corrupt you file if using JSON . If you wish to both preserve old data and still use JSON format you might try something like loading the data first, parsing it, merge together with the new data and then overwrite the file.
@SaSeshen
@SaSeshen 3 жыл бұрын
I have watched, and read several videos/tutorials on the Save and Load function, but they all discussed binaries as the primary mechanism, why would I want a JSON over Binaries or vice versa?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
JSON is text which makes it easy to read and edit and is understood by a massive amount of programs. Unity already has those built-in functions to deal with it. Binary requires you to organize the data yourself which can be more tricky. In my games I normally use Binary since I can set it up exactly as I want it without any wasted space which greatly reduces file size. In the end they both achieve the same result, store data.
@boraozenbirkan6853
@boraozenbirkan6853 3 жыл бұрын
​@@CodeMonkeyUnity Would you make a video about storing as binary as well since you're normally use it you can teach quite good tips and tricks :)
@boraozenbirkan6853
@boraozenbirkan6853 3 жыл бұрын
​@@CodeMonkeyUnity By the way, you're helping the world to become a better place by sharing your knowledge. I've learned a lot from you. Thanks for that!
@icyicecream7482
@icyicecream7482 5 жыл бұрын
How would you go about serializing sprites? Right now, when i save the sprite it writes an instance id for the sprite, but when i load it again it returns null. Thanks in advance
@icyicecream7482
@icyicecream7482 5 жыл бұрын
It seems the only way is to save the sprite's path instead
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
A sprite is byte data whereas JSON only saves strings. You can use base64 encoding to save a sprite as a string. byte[] byteArr = myTexture.EncodeToPng();string encodedText = Convert.ToBase64String(byteArr); byte[] b64_bytes = System.Convert.FromBase64String(encodedText); tex = new Texture2D(1,1);tex.LoadImage(b64_bytes); Or like you said if the sprite isn't custom just save the path.
@icyicecream7482
@icyicecream7482 5 жыл бұрын
@@CodeMonkeyUnity Thank you very much!
@DanielAbeleira
@DanielAbeleira 4 жыл бұрын
How would you extend this to more than just one object? I'm planning a city building game and I need to load the assets that the player placed where they were placed
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Store an array of Save Objects inside your main Save Object
@yasserahmed7861
@yasserahmed7861 Жыл бұрын
That's why he is the GOAT, THE GOAT
@blablu2475
@blablu2475 3 жыл бұрын
The type or namespace name 'IUnit' could not be found (are you missing a using directive or an assembly reference?) Help me pls
@mawebbzz
@mawebbzz 3 жыл бұрын
Hello, I was wondering - I've watched all your videos on saving and loading but I'm interested in knowing which is the most suitable method between usinf files+json, playerprefs or binary formatter?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
File + JSON is the best method unless you have a very specific use case or some giant files..
@avdya7582
@avdya7582 2 жыл бұрын
@@CodeMonkeyUnity binary is better,at least coz your files are more protected
@BriShep123
@BriShep123 2 жыл бұрын
@@avdya7582 BinaryFormatter is now unsafe to use as it is a potential security loophole.
@teamdoodz
@teamdoodz Жыл бұрын
@@avdya7582 "More Protected" is a fallacy. Binary saves are more obscured, yes, but anyone who has access to your code (which is easy, since C# is easy to decompile) can just copy your code over to make a save editor.
@teamdoodz
@teamdoodz Жыл бұрын
@@BriShep123 Yes, but BinaryReader and BinaryWriter are very much safe.
@ohj6878
@ohj6878 2 жыл бұрын
hi , why do you use a constant in your save system ? what's the point of doing that ?
@vizualwanderer
@vizualwanderer 3 жыл бұрын
Question: is one directory/save path name enough or, are there more needed per object, when working with bunch other objects? can you use /save.txt for other than player attributes/saveObject... say you are working with inventory values, can that as well be saved in /save.txt? (i am aware you have to call a spastic path to load what you need, but can EVERY save be in one path)
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
Usually what I do is create a global Save Object and in that object I include whatever data I want, player, inventory, game progress, etc. And I save/load that global Save Object.
@vizualwanderer
@vizualwanderer 3 жыл бұрын
@@CodeMonkeyUnity sorry for not replying sooner... thanks for replying and very good method!
@herzogtwo
@herzogtwo 3 жыл бұрын
if i import the utilities and this project unity say missing prefab and i have a black background
@dav
@dav 5 ай бұрын
I watched this because of your latest quiz video that you just published. Coming from web dev, json is already baked into the day to day. So it’s cool that Unity embraces just as much. Question for you is does it easily integrate with Steam cloud saves? Thanks for all you do!!
@CodeMonkeyUnity
@CodeMonkeyUnity 5 ай бұрын
Yup you can store a string in Steam cloud save, it stores bytes so you can easily convert a JSON string into bytes and save a file
@CSPlayerDamon
@CSPlayerDamon 4 жыл бұрын
Hello, I know this is a basic tutorial, but I've figured I'd ask. Isn't FIle.WriteAllText a synchronous operation? Meaning that, if, for any reason, the data was too big, it would freeze the application until the writing is done. In these situtations, an async write to the file would be preferable.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Yes if your file is too big to be saved in under 1s then you should show a "Saving" visual and do it asynchronously.
@Sandflowgames
@Sandflowgames 2 жыл бұрын
Cool tutorial very helpful. i was going to use binary but binary is unsafe when deserializing so yeah!
@The_Peprechaun
@The_Peprechaun 4 жыл бұрын
What object is meant to be assigned to the 'Unit Game Object'?
@unvisibleone5367
@unvisibleone5367 5 жыл бұрын
Its so good but sooooooooooo hard Thanks
@dav
@dav 5 ай бұрын
Another question is how well does it convert custom classes into json string? Do you need an equivalent of a ToPlainObject() or ToString() in your classes? It is good to see there are some basic conversions built in like Vector3
@CodeMonkeyUnity
@CodeMonkeyUnity 5 ай бұрын
As long as it's marked as [System.Serializable] it should work for almost anything. The only thing that doenst' work that I know of is Properties, I've had some very frustrating times trying to understand why something wasn't saving/loading, it was because it was a property and not a variable
@alecson95
@alecson95 4 жыл бұрын
Referencing from your Inventory video, Do I write the item.itemtype and item.amount into the SaveObject class? I'm trying to save the amount of the items that correspond to the itemtype. Pretty stuck on this for days trying to figure out how to accomplish this! Please help!
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Yes, create a SaveObject class to hold your ItemType and the Amount and save a list of that for every item in your inventory.
@changemaker9751
@changemaker9751 4 жыл бұрын
First of all , i want to thank you for this video .I learnt a brand new thing to use in unity but i didnt get how you store json data in txt extension file ? Can you pls explain me how this happened? And Secondly, you can easily use commands in System.IO namespace.Is there a way of learning these commands in any page.Because you know Unity doesnt use these namespaces unless it needs
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
JSON data is just text, the file extension you save as doesn't matter, it can be .txt or .json or anything you want. You can view all the C# classes and functions in the Microsoft Docs docs.microsoft.com/en-us/dotnet/api/system.io?view=netframework-4.8
@B4NTO
@B4NTO Ай бұрын
Do you have a good recomennded video for saving the prefab? I have created a save system for saving all my trees position, rotation but how can i grab each instance prefab and use that when i instantiate it on loading them all?
@CodeMonkeyUnity
@CodeMonkeyUnity Ай бұрын
You save some kind of identifier for that prefab. What type is it? Normally I make List for each object type. So for example in my game Dinky Guardians I have a list for all the Dinkys, another list for all the Machines, etc. So when loading I know which list I'm going through and know which specific prefab to spawn.
@B4NTO
@B4NTO Ай бұрын
@@CodeMonkeyUnity Thanks. I have a list where i gather all trees in the entire scene of GameObject type with tag SavedTrees and loop through them and save their position, rotation, scale but then yesterday i started to save their names so that i could find what ever their prefab was named inside of the Resources/Props/Nature with the GameObject prefab = Resources.Load("Prefabs/Props/Nature/" + treeData.prefabName); Not sure how good this will be in the long run but what i noticed is that when i saved all my trees the second time because of how Unity does instantiate I had to also remove some of the string when trying to get the correct prefab name, im very new to the entire saving process but trying to find a way for Unity to figure out which prefab to use without hard setting references because I will have many kinds of trees, bushes, crops etc in my farming game. This is were i currently fix the name to get the prefab name correctly after the first time save, load then the (Clone) is added to the gameobject in scene which needs me to remove it, it seems to work pretty well so far but not sure how scaleable it will be later on. private string GetPrefabName(GameObject prefabObject) { string name = prefabObject.name; if(name.EndsWith("(Clone)")) { name = name.Substring(0, name.Length - 7); } return name; } this is what the treeData.prefabName is set to
@kunz4164
@kunz4164 3 жыл бұрын
How would you save a list of things to JSON? I have a party system so it has list of characters and I would like to convert those to JSON and then back to character objects for saving and loading purposes.
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
If the underlying object is Serializable then it can be saved, make a SaveObject that stores only the data you need to then load it. I'm not sure if lists are serializable by default but you can just convert it into an array
@sherlyhudson2198
@sherlyhudson2198 3 жыл бұрын
Since this is an old video, Idk if you will see this but is there a way to encrypt the save files?. Cause technically people can change the save file data by opening it in a txt file and editing the variables right? And thank you for your videos, they are really helpful for beginners like me.
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
Yeah JSON by itself is not intended to be secure at all, it's just text. You can definitely apply some encryption on top, either some text encryption or convert the final JSON into bytes and encrypt that.
@sherlyhudson2198
@sherlyhudson2198 3 жыл бұрын
@@CodeMonkeyUnity Do you think you can show me an example of how that works? I tried searching for some examples regarding unity saving and loading with JSON then encrypting but having no luck. Some talk about other things, others just don't make much sense.
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
@@sherlyhudson2198 JSON is just text, so just find one of the many libraries for doing text encryption. But I would also say don't worry about that, if you're making a single player game then don't worry if the player decides to cheat, it's not worth the time to try to stop that.
@captainufo4587
@captainufo4587 5 жыл бұрын
Would you please consider making an extra turotial that shows a slightly more complex version that shows how to expand the system to save multiple objects at once (say, more than one character doing different things, the state of the mining nodes, a building in progress, whatever, or any combination of those)? I can sort of already do that myself and I already monkeyed (no pun intended) with it, but I can't help but second-guess every single line of code I write for the expansion and ask myself if there isn't a less cumbersome way of dealing with the problem (mostly because all the tutorials out there end more or less at this exact point, so I have nothing to compare to and see if I'm dong it the right way or in an unnecessary roundabout way. I have yet to find the files/explanations for a more complex savegame system I can study).
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
Yup I would like to do a series on an Advanced Save System covering the various things I use in my own games. How you set up your save is very dependent on what your game needs saving. In the case in the video, if I wanted to save the positions of all the gold nodes I would add to the SaveObject: List goldNodePositionList; If you wanted to save more information from the gold node you could have a GoldNodeSaveObject: [System.Serializable] class GoldNodeSaveObject { public Vector3 position; public int resourceAmount; } Then back in the SaveObject add List goldNodeSaveObjectList; That's normally how I do things, the entry point for my save system gathers all the save objects from all the main systems in the game which in turn gather the save objects from their own objects and so on.
@captainufo4587
@captainufo4587 5 жыл бұрын
Great, thank you! Yeas, what needs to be saved is the real issue for me. I like city/empire/society builders/simulations, and I always end up with this large quantity of data from different gameobjects that needs to be packed, and that creates a somewhat unwieldy savegame object, which in turn is a bit headache-inducing when you need to unpack all the stuff and reinitialize all the data to the correct values on load. I'd just love to be able to get my hand on a real complex savegame system to see if I just have to endure the headache, or if I'm making it innecessarily harder for myself.
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
@@captainufo4587 When it comes to management/building games it certainly requires enduring the headache. You do need to be very deliberate about Saving and Loading each specific object and correctly saving and loading the data that object uses. So start from the top and move down each level saving one by one. On the main save you have fields for BuildingsSave, WorkersSave, ResourcesSave Then the BuildingsSave you get from a BuildingHandler class that manages all buildings From that class you get the SingleBuildingSave for each specific building That SingleBuildingSave then contains the building data, resources stored, workers working there, etc. Go slow and focus on one single thing at a time, first get the saving and loading of a single building working, then put it in a list and save and load all buildings, then do the same for the workers and so on.
@spxctreofficial
@spxctreofficial 3 жыл бұрын
If I replaced "/save.txt" with "/save.customfileformat", would it break the code? It would be very convenient if I could use a custom file format instead of .txt, indicating that it would harder to modify.
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
The extension name doesn't matter, you can use whatever you want, it doesn't change the underlying data
@spxctreofficial
@spxctreofficial 3 жыл бұрын
@@CodeMonkeyUnity alright, just making sure, since I was uncertain that JSON worked differently and required a specific file format such as TXT to function properly, Thanks!
@juanpedraw4245
@juanpedraw4245 Жыл бұрын
Watching this right after your 'What is JSON?' video feels like going from 1 to 10^10 very quickly.
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
How so? What part are you finding hard to understand? It's all pretty straightforward, JSON is a text-based data format, Unity has 2 functions to easily convert to and from JSON, so all it takes it defining the structure of the data and you can easily save and load.
@mmokzlrsn
@mmokzlrsn 11 ай бұрын
i will use this system for my grid inventory system i hope this works
@general_md
@general_md 3 жыл бұрын
Hi, I am making a farming game where you can buy trees from a shop and they get instantiated in the scene, but the problem is that after exiting the game, the instantiated prefabs (trees) get destroyed. I wanted to know I there is a way by which I can save the gameObjects instantiated in the scene and also their positions, cuz they are draggable. I looked up at Google and KZbin but found nothing. Could you please tell how to do it or make a video so that anyone working on a project like this gets help
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
This video shows you how to save and load, just store the position in the save object
@liangzou198
@liangzou198 5 жыл бұрын
What should I do if I want to save the List?
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
Create an object that holds a list of Vector3s and then store a list of that object, you just need to add [Serializable] to your custom object. private class JsonTest { public List vectorList; [Serializable] public class VectorList { public List vecList; } } JsonTest jsonTest = new JsonTest { vectorList = new List { new JsonTest.VectorList { vecList = new List { new Vector3(0, 1) } } } }; Debug.Log("######## " + JsonUtility.ToJson(jsonTest));
@liangzou198
@liangzou198 5 жыл бұрын
@@CodeMonkeyUnity It works! Thank you very much!
@dmarshallgaming
@dmarshallgaming Жыл бұрын
Hello! Thanks for all the great knowledge! I've done a few of your courses and watched a lot of your YT tuts :) Question: How would you save multiple objects into the JSON file? Explanation: I'm saving an array of PlacedObject_Done SaveObjects ( PlacedObject_Done.SaveObject[] ) with 4 variables defined in the PlacedObject_Done.cs SaveObject class. I also want to save an array of values for resources ( [0] = value, [1] = value, etc ). So then I have another array of SaveObjects ( CityManager.SaveObject[] ). Is it possible to (or correct) to comine those SaveObjects into a new array? So I guess, an array of arrays...? Just trying to figure out how to wrap everything into one JSON save file. Thank you!
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
Yup exactly, you can save an array of save objects, they will all be serialized and when loading you will get that array back. Usually in my games I have one master SaveObject which in itself contains the other SaveObjects the game uses. So the main SaveObject would have a field for a ResourceManager.SaveObject then perhaps a EnemyManager.SaveObject, etc For example I saved some game data and screenshot data in this video unitycodemonkey.com/video.php?v=dqySkMFieHE
@dmarshallgaming
@dmarshallgaming Жыл бұрын
@@CodeMonkeyUnity Awesome, thank you!
@SMGtk
@SMGtk 3 жыл бұрын
I am making a game where there are a lot of data to be kept save. Should I keep all of it in SaveObject as attributes? or is there are better method? For instance I have a shop and shop has money making rate and max capacity, another thing I have a some cage and all cages have different type of animals. and many things like this. How can I save them?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
Yes storing all that data in a Save Object is fine, only if you have a massive amount of data, like 10MB+ would you perhaps need another method
@azkalanken4194
@azkalanken4194 Жыл бұрын
How do you save json if you are building for webgl ?
@Icy_T
@Icy_T 5 ай бұрын
Would Newton be a better than JSON utilities? I heard Newton was the best option from another source and I wanted your opinion on it
@CodeMonkeyUnity
@CodeMonkeyUnity 5 ай бұрын
I think Newton might be more performant, but for most cases JsonUtility works perfectly fine
@amazeinggames
@amazeinggames 4 ай бұрын
@@CodeMonkeyUnity Still answering questions from a video that came out 4 years ago. I salute you King o7
@Nick-bf8ke
@Nick-bf8ke Жыл бұрын
Hi, will this work in 2 different computers? Let's say it is a steam game and it's installed on your pc and laptop. if you save progress on pc it will not be saved on laptop even though you are using the same steam account, am I right? So what is the solution in this case? use cloud server to save data?
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
Cloud saves would be built on top of this system. You save the data locally into a file, then using something like Steam Cloud Save you upload the save file to the cloud. On the other laptop you would download the cloud save and load it just the same.
@StarkTech47
@StarkTech47 3 жыл бұрын
Hi very cool video but I asked myself, why creating a SaveObject class to store data from our player and put this SaveObject into JsonUtilities instead of putting our player object directly into it ?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
It's so you can choose what type of data you want to save. If you try to directly convert a complex object into JSON you'll get a lot of useless data
@StarkTech47
@StarkTech47 3 жыл бұрын
@@CodeMonkeyUnity Ok so it's possible but it's better to select only variables that I will use
@xoduk
@xoduk Жыл бұрын
How would this work with an Array? I have an 8x8 grid board and an array containing each piece with gridX, gridY of the array being set to that piece. So for example the piece at 5, 7 is Piece[5, 7] with the array length being 64
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
It would work just the same, put an array inside your save object, the only thing you need is to make sure the type inside the array is serializable. So instead of storing a reference to the piece game object make some kind of enum to define the piece type.
@xoduk
@xoduk Жыл бұрын
@@CodeMonkeyUnity Ok, I'll try that when I get a chance. Thanks!
@dnscdnsc6121
@dnscdnsc6121 3 жыл бұрын
Hello Codemonkey, I'm a little bit confused about how to save game data to another scene. like the data from the scene1 should have the same data when the player enter another scene (scene2). I'm looking forward for your answer.
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
You can make it as a static field
@dnscdnsc6121
@dnscdnsc6121 3 жыл бұрын
@@CodeMonkeyUnity do you have a tutorial on that?
@dnscdnsc6121
@dnscdnsc6121 3 жыл бұрын
for example, when a player meets an enemy in an open world the scene changes to a turn-based battle system, all I need is how to preserve the data before and after the battle.
@inheritorofthewilloffire2547
@inheritorofthewilloffire2547 3 жыл бұрын
Thank you so much for posting this video! This is a tremendous help for beginners to Unity like me! I wanted to ask you, I downloaded the package from CodeMonkey and have implemented it. However, when I hit 'S' or 'L', the save or load doesn't seem to work for me. Do you have any idea why this is or what I can do to fix this?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
Use Debug.Log to see what your code is doing, are you capturing input correctly? Is it correctly converting the JSON? kzbin.info/www/bejne/a5rVp2ZmYseHgNk
@inheritorofthewilloffire2547
@inheritorofthewilloffire2547 3 жыл бұрын
@@CodeMonkeyUnity Thank you for taking the time to reply to help me with this! Okay, so I watched your video and it's a tremendous help. I was able to reference the object in Unity because initially it was NULL, however, the issue for me still persists. I'm continuing to look into it to see if I still have NULL references and see if I'm correctly converting the JSON.
@inheritorofthewilloffire2547
@inheritorofthewilloffire2547 3 жыл бұрын
@@CodeMonkeyUnity Hi, I wanted to send this reply to let you know that the video you sent me helped me resolve what I had wrong. Thank you so much!
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
@@inheritorofthewilloffire2547 I'm glad it helped!
@samuelmccloy9334
@samuelmccloy9334 3 жыл бұрын
set up all utilities but can't get my player position to save also getting a NullReferenceException: Object reference not set to an instance of an object GameHandler.Save () (at Assets/SaveLoad/Scripts/GameHandler.cs:42) GameHandler.Update () (at Assets/SaveLoad/Scripts/GameHandler.cs:32)
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
You have something set to null, use Debug.Log to find out what kzbin.info/www/bejne/a5rVp2ZmYseHgNk
@slademore1219
@slademore1219 Ай бұрын
Hey code monkey I'm having an issue with the absense of the IUnit script but you dont show that in this video, can you please help me here?
@CodeMonkeyUnity
@CodeMonkeyUnity Ай бұрын
That's an interface, you can implement it in any way you want, you can use whatever character controller you want
@Pan9026
@Pan9026 3 жыл бұрын
but what if i use BigDouble instead?(not a double but a created script for double where it can hold infinite number digits such as 'public BigDouble coins')
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
Just mark your custom classes as Serializable and they will save as usual
@Dxstin
@Dxstin 3 жыл бұрын
Can you make a video where you explain how to create an autosave system? For example that everything is saved every 10 minutes? And when I click on a button, the last save is loaded.
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
The only tricky part is just figuring out what you want to save, when you have saving working perfectly then you just apply a simple timer to it and save as often as you want
@null21235
@null21235 3 жыл бұрын
u need calculate by using Time.time or invoke your function within 10 minutes
@VELI-Productions
@VELI-Productions 2 жыл бұрын
So I don't know if anyone else has ran into this, but let's say I build the game for Mac, it runs perfectly on there, I zip it up and upload it to a place like Google Drive, Dropbox, etc., when I download it again and try to run it, other than telling my Mac that I trust the developer, I get a file permissions error in the debug console. "xattr -r -d com.apple.quarantine path/to/game" fixes it, but I don't want other people to have to do that after downloading it. Any suggestions?
@BrandonBrady97484
@BrandonBrady97484 Жыл бұрын
Does this work with webgl builds?
@rafaelladeia7278
@rafaelladeia7278 2 жыл бұрын
Hey! Thanks for the awesome content! One question: do you see some kind of problem when applying this technique into augmented reality apps? I'm creating an android AR app which aims to create continum sessions, but the SDK that I'm using don't support this function.
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Doesn't support what function? Saving a File? Converting JSON?
@rafaelladeia7278
@rafaelladeia7278 2 жыл бұрын
@@CodeMonkeyUnity No. I mean ARCore (Google API for Android AR Apps) doesn't have a functionality of save and load session, as ARKit (Apple) has, which is called ARWorldMap. So, to workaround this I'm trying to use conventionals saving systems (like you presented in the video) to to save and load AR sessions. Thanks for your attention!
@opalakadewa4679
@opalakadewa4679 3 жыл бұрын
Ummmm.... Is anyone missing the player prefabs after importing the package ?
@juanconde9323
@juanconde9323 3 жыл бұрын
hello!, this can use if file is online??? thanks!great video suscribe
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
I covered how to download online data here kzbin.info/www/bejne/fZyTXpSjm9Noeq8
@maxo7798
@maxo7798 5 жыл бұрын
how you go about showing list of available save?
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
You can use System.IO.GetFiles(path); to return all file names in your save folder. docs.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=netframework-4.7.2
@user-gg1wk1fx4b
@user-gg1wk1fx4b 5 ай бұрын
Everything works well in the editor, but when I use the assembly in WebGL, the download does not see my saves, how can I make it see it?
@CodeMonkeyUnity
@CodeMonkeyUnity 5 ай бұрын
WebGL usually has some very limited permissions when it comes to saving files, so for that format using PlayerPrefs is probably the easiest way to save
@user-gg1wk1fx4b
@user-gg1wk1fx4b 5 ай бұрын
Thank you very much for your answer, saving through the Binary formatter in format dat worked for me, but not quite correctly, they already suggested a plugin for my platform)
@MarushiaDark316
@MarushiaDark316 4 ай бұрын
@@CodeMonkeyUnity Is the issue with WebGL because you're using .dataPath instead of .persistentDataPath? I'm really not sure what the difference is between those or even .streamingPath. I know .dataPath saves to the Assets Folder, whereas persistent says to some place that's unique to each device. Most of the explanations online are pretty opquae and hard to understand. Would appreciate if you could do a revised version of this that dumbs down each of these, as well as covering Cloud Save and also making save objects that use generics, as sort of a stepping stone off of this.
@vergilw7009
@vergilw7009 2 жыл бұрын
Hello Code Monkey, this Tutorial is so great, however, if I want to make the loading system can showing all the saving data slot on list, then choose which data slot should load by clicking it , how to do it ??
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
You can use Directory.GetFiles() which will return all the save files in your save folder. Then cycle through it and display a button for each of them
@vergilw7009
@vergilw7009 2 жыл бұрын
@@CodeMonkeyUnity Hello, I tried String noOfFile; Debug.Log (noOfFile = Directory.GetFiles (SAVE_FOLDER).ToString ()); but it only shows "Debug.Log(Object)"
@MB-nw8wu
@MB-nw8wu 3 ай бұрын
do you recomend json over binary or xml ?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 ай бұрын
Any of those can work, I find JSON the simplest of all so it's what I use in my own games
@alessandrozoppi8597
@alessandrozoppi8597 3 жыл бұрын
Hi Code Monkey I became a Patron but i cannot see all the courses with the project files there... Where I can download them? Thanks for reply
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
There's a link in the description, for this video it's at unitycodemonkey.com/video.php?v=6uMFEM-napE
@nguyennhat6970
@nguyennhat6970 5 жыл бұрын
Hi!when i just imported the package, I have a bug: The type or namespace name `CodeMonkey' could not be found. Are you missing an assembly reference? Please help!
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
The CodeMonkey namespace is the Utilities, you can grab the unitypackage from the website. Cheers!
@Only4GamersXyz
@Only4GamersXyz 2 жыл бұрын
Hello, How to delete a SaveObject file from directory?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Use File.IO.Delete();
@zekiozdemir420
@zekiozdemir420 2 жыл бұрын
they say that binary shouldnt be used for save files is that correct? and thank you for the video.
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Where did you hear that? And with regards to what? Every format has it's pros and cons, binary is just basic data
@eladonstar2721
@eladonstar2721 2 жыл бұрын
what if the user changed the data from the text file we are storing the information?...
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
If your concern is security then yes JSON is not what you're looking for. But in most cases if you're making singleplayer games then it's a waste of time to try to stop the player from cheating their own game. If they want to manually edit their save files so they have more money or resources just let them do that.
@rauljerilara8848
@rauljerilara8848 2 жыл бұрын
is it works on android too?
@lolcat69
@lolcat69 3 жыл бұрын
thx, now my own "Mii creator" can save and load the "Mii´s" than you make
@RealBurgunfaust
@RealBurgunfaust 4 жыл бұрын
@7:55 the static const I am getting an error message UnityException: get_persistentDataPath is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'GameHandler' on game object 'GameHandler'. See "Script Serialization" page in the Unity Manual for further details. GameHandler..cctor () (at Assets/Scripts/GameHandler.cs:10) Rethrow as TypeInitializationException: The type initializer for 'GameHandler' threw an exception.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
You should not add a constructor to a script that also extends MonoBehaviour
@RealBurgunfaust
@RealBurgunfaust 4 жыл бұрын
@@CodeMonkeyUnity public class GameHandler : MonoBehaviour { PlayerData loadedPlayerData = new PlayerData(); public PlayerData playerData; private static readonly string DATA_FOLDER = Application.dataPath + "/Data/"; [...] this is whats giving me the error: UnityException: get_dataPath is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'GameHandler' on game object 'Data'. See "Script Serialization" page in the Unity Manual for further details. GameHandler..cctor () (at Assets/Scripts/GameHandler.cs:11) Rethrow as TypeInitializationException: The type initializer for 'GameHandler' threw an exception.
@ArzenikRawr
@ArzenikRawr 2 ай бұрын
Im trying to save a ui canvas but im unsure if this will work
@CodeMonkeyUnity
@CodeMonkeyUnity 2 ай бұрын
You can't save a Canvas, a Canvas is a component. What you can save is whatever data you're displaying on that Canvas
@akshatmishra8336
@akshatmishra8336 2 жыл бұрын
how to save multiple player position
@user-tx4tu4jl7v
@user-tx4tu4jl7v Жыл бұрын
Hello, can meshes be saved? cause even though the mesh gets the same instance ID on save and load,it isn't loading correctly.
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
The type Mesh is a reference type so you cannot directly convert it into a serializable type and save it in text. What exactly are you trying to do? Are you really trying to save a Mesh? Or just need to save what type of Mesh it is? If you just need the type then save some kind of identifier for that mesh, some kind of unique name. If it's a custom dynamically generated mesh that you really want to save then you would need to save the components. Save the mesh.vertices, mesh.uv and mesh.triangles That's basically how I save my Animations in my custom animation system unitycodemonkey.com/video.php?v=11c9rWRotJ8
@user-tx4tu4jl7v
@user-tx4tu4jl7v Жыл бұрын
@@CodeMonkeyUnity thanks for the answer , i 'm trying to save-load an inventory system where every slot has its variables of the represented object ,then i save and load all the variables of the slot, one of the variables is the mesh of the represented object, the mesh that allready is in the project files not a dynamicaly generated one,so if i got it right i need to save mesh.vertices,uv and triangles and constract new mesh on load? im asking again because im a little confused by your answer (if its a custom dynamically generated mesh - then save mesh.vertices etc,) if its a mesh from the project files can I serialize it? thanks again for your time. Edit: oh wait ,do you mean that i should give all the project meshes a unique integer on runtime? Keep them on a game object list for example? and just save the integer and then reference it? if that's the case , there are hundrends of meshes in the project ,is that the case? Sorry for the many questions,its just the last thing i need to do to complete the system.
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
​@@user-tx4tu4jl7v Yes if the mesh is not dynamically generated, if it always exists just the same in the project files, then all you need is to assign some sort of id to it and just save that id. Then when loading find out what mesh that id belongs to
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
​@@user-tx4tu4jl7v Yes if the mesh is not dynamically generated, if it always exists just the same in the project files, then all you need is to assign some sort of id to it and just save that id. Then when loading find out what mesh that id belongs to
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
@@user-tx4tu4jl7v Maybe use a an array of Meshes and use the array index as the id, or perhaps something like a ScriptableObject that stores a string name and a mesh reference unitycodemonkey.com/video.php?v=7jxS8HIny3Q
@iamvironic
@iamvironic 2 жыл бұрын
this line still generates an error! private static readonly string DAILY_DIR = Application.dataPath+ "/Saves/";
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
what error?
@loe2630
@loe2630 2 жыл бұрын
@@CodeMonkeyUnity I too get an error: get_dataPath is not allowed to be called from a MonoBehaviour constructor (or instance field initializer)
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
@@loe2630 Did you make it static readonly instead of const?
@dasmaffin1633
@dasmaffin1633 5 жыл бұрын
You should do this for binary too
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
Yeah I would like to do a video on a advanced Save System that saves directly in bytes. Its harder to do but the final file has a smaller size.
@tomershmaya8852
@tomershmaya8852 4 жыл бұрын
@@CodeMonkeyUnity and it's safe from player's meddling (in a text/JSON a player can add gold for himself, for instance). Was such a video created since?
@thefreshcarrot4940
@thefreshcarrot4940 2 ай бұрын
Great tutorial, but I'm wondering how to save and load not just the position but the directions the player is facing
@CodeMonkeyUnity
@CodeMonkeyUnity Ай бұрын
It's the same thing, direction is a Vector3 just like position. So grab the transform.forward and save that
@thefreshcarrot4940
@thefreshcarrot4940 Ай бұрын
@@CodeMonkeyUnity And I forgot to ask what about animations
@CodeMonkeyUnity
@CodeMonkeyUnity Ай бұрын
You don't save the animations themselves, if you want to save the animation you save just the state. Could be a simple string "AttackAnimation" or "AttackAnimation" at 0.2s
@Eltsuyt
@Eltsuyt 3 жыл бұрын
How can i make something like if i press D, save will be deleted?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
Use File.Delete();
@Eltsuyt
@Eltsuyt 3 жыл бұрын
@@CodeMonkeyUnity Thanks!
@plbm2285
@plbm2285 3 жыл бұрын
How do i save GameObjects like when i spawn a house while playing how do i save this? Please help me...
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
Create a save object with the data you want to store and handle the logic for recreating that data when loading
@plbm2285
@plbm2285 3 жыл бұрын
@@CodeMonkeyUnity I downloaded the Project files but The type or namespace name 'CodeMonkey' could not be found... how can i get this from you?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
@@plbm2285 That's the Utilities which you can also download from the website
@info.matters
@info.matters Жыл бұрын
Iam a beginner in unity , how to show the saved data in main manu
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
Depends what data you want to show. You can open the file and read it while in the main menu
@Sandflowgames
@Sandflowgames 2 жыл бұрын
the json saving works in unity editor but not in unity build????
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Check your logs, you're probably getting some error with a non existent file kzbin.info/www/bejne/aKXEamCEaNCpj9U
@Sandflowgames
@Sandflowgames 2 жыл бұрын
It was cus I put datapath not persistentdatapath
@hasanprakash
@hasanprakash 3 жыл бұрын
what is IUnit here??
@amgames5638
@amgames5638 2 жыл бұрын
Do you know how to POST a JSON file via an API? Or do you have a video on how to do this, I only saw one on how to do it with JAVA lol. I know how to do a Get request from an API, but I need to send a JSON file with 4 variables to a URL....
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
With UnityWebRequests you can contact an external server and send whatever data you want kzbin.info/www/bejne/fZyTXpSjm9Noeq8
@amgames5638
@amgames5638 2 жыл бұрын
@@CodeMonkeyUnity Thanks for the response, sorry, I'm kinda dumb when it comes to web requests. I know how to send a download request and get the JSON file from it, but is it just the same idea but using the "Post" method in the UnityWebRequest class? And I just pass in the JSON converted to string that I want to post?
@MAMFMAHMOUD
@MAMFMAHMOUD 5 жыл бұрын
that's a great way to save data, but it's not secure, anybody can change the save file if he had a little knowledge about json, any way to encrypt that json file, I would appreciate that :)
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
Yup that's correct, the saves stored in this way are easily editable so you could edit a save and suddenly have infinite gold or something. I only make Single player games so for me security of the save data generally isn't a concern, if someone wants to cheat on their own game by all means let them do it. If you have a game where you absolutely need to secure data the only real solution is to store that data in a server. Anything stored locally will eventually be decrypted. Cheers!
@MAMFMAHMOUD
@MAMFMAHMOUD 5 жыл бұрын
Ok, thanks for the reply anyway :)
@ZoroastrianMK
@ZoroastrianMK 5 жыл бұрын
That's true, the most used aproach is to create a binary file so you can write and read without any problem in it, but no one else can decode it.
@MAMFMAHMOUD
@MAMFMAHMOUD 5 жыл бұрын
ZoroastrianMK if you mean saving the save file in binary insted of saving at as json, well that's also an unsecure way of saving, cuz almost every programer can read binary, and if he doesn't,he can decode it easly in any software or website :)
@theforgot3n1
@theforgot3n1 4 жыл бұрын
@@CodeMonkeyUnity It's true it will eventually be decrypted but doing a simple encryption I do think would deter 95% of people who might wanna change their save file out of cheapness or frustration.
@Sandflowgames
@Sandflowgames 2 жыл бұрын
Also do i need a json namespace or not?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
JsonUtility is inside UnityEngine so that's all you need
@Sandflowgames
@Sandflowgames 2 жыл бұрын
Oh ok also I found out how to make custom files with Json like .sav and stiff
@jeongsatzu
@jeongsatzu 3 жыл бұрын
do properties work on JSON Utility?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
Well a property has a field behind it so you can save that. But if you're asking about automatic properties, those are set as private so I don't think they would work.
@Exisss
@Exisss 4 жыл бұрын
Is command saving game data then quited it?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
The Save data is in a file so it does persist between sessions.
@Exisss
@Exisss 4 жыл бұрын
@@CodeMonkeyUnity and 1 question again, did u made a video, to make player move with joystick (for android/ios) (move ⬆️➡️⬇️⬅️)
@jaxxrr
@jaxxrr Жыл бұрын
what if I have an array of objects ?
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
You can save a List as long as the SaveObject has the attribute [Serializable]
@laurynas6806
@laurynas6806 4 жыл бұрын
Save object is gonna return save object and do save object
@davideloreto4597
@davideloreto4597 3 жыл бұрын
Does json supports array?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
Yes
@unvisibleone5367
@unvisibleone5367 5 жыл бұрын
Can you make learn some commands
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
What do you mean learn some commands?
@MAMFMAHMOUD
@MAMFMAHMOUD 5 жыл бұрын
Maybe that's a better way of doing it ? public void Save(T saveClass, string savePath) { string saveData = JsonUtility.ToJson(saveClass); File.WriteAllText(savePath + @"\Save.txt", saveData); } public T Load(string loadPath) { T saveFile = default(T); string saveData = ""; if (File.Exists(loadPath)) saveData = File.ReadAllText(loadPath); else { Debug.Log("No save file found !"); return saveFile; } saveFile = JsonUtility.FromJson(saveData); return saveFile; } by creating a save class and putting all the information you want to save as variables in that class, and those functions above takes the type of class (T) and just converts it to\from json.
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
Yup that's a great way of doing it, I kept the video simple but for your own projects that function will be more helpful since different objects will have different SaveObject classes. Cheers!
@walney2008
@walney2008 4 жыл бұрын
very good, unity save and load MySQL ? , all player the game, unique save, session Player ? i´m study game in my site webGL, sabe unique player , what ? i´m from Brasil, sorry my ingles.
@suicune2001
@suicune2001 2 жыл бұрын
Thanks! But how the heck do you DELETE the save file? Everyone talks about saving and loading but how do you delete the saved file and start from scratch? EDIT: Never mind, I figured it out on my own! YAAAY! :D Just attach this function to the delete button: public void DeleteSaveData() { File.Delete(Application.persistentDataPath + "/savefile.json"); }
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Yup that's it use File.Delete();
@trojan3812
@trojan3812 4 жыл бұрын
Can I use this saving system on an android game?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Sure, as long as you write your save files where you have permissions.
@ez4novi
@ez4novi 4 жыл бұрын
@@CodeMonkeyUnity Hi how would I do that it seems I have the saved file, then I want to load it in startup it seems to work in Unity Editor but when I tested it on android its not loading it.
@DIEGOGARCIREBOLLO
@DIEGOGARCIREBOLLO 4 жыл бұрын
@@ez4novi to write a file in Android you should use Application.PersistentPath, Wich will direct the path to the internalStorage/Android/Data/com.YOURCompany.YourProject/files/UnityCache/Shared/ From there it depends if you're using a caching state or just plainly writing the file
@ez4novi
@ez4novi 4 жыл бұрын
@@DIEGOGARCIREBOLLO thank you but I already found a way which is the resource load file this keeps the user to edit the file save externally. Thanks for sharing your way though
@Rhino123freak
@Rhino123freak 4 жыл бұрын
@@ez4novi can you explain your way? I didn't understand it properly.
@fun4mylife
@fun4mylife 9 ай бұрын
I love your videos but this one I find difficult to learn from because you start it in the middle of existing code and then delete code to make it better. I'll figure it out... just my thoughts.
@CodeMonkeyUnity
@CodeMonkeyUnity 9 ай бұрын
This video was a really long time ago but I think I started the save logic from scratch in the first video on the playlist kzbin.info/aero/PLzDRvYVwl53vRrMuPBkNNZUmnl1jCHcHs
@Tamdev9
@Tamdev9 5 жыл бұрын
how can i save enum to json?
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
Just save it normally, JSON supports enums.
@Tamdev9
@Tamdev9 5 жыл бұрын
@@CodeMonkeyUnity can give me example?
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
Just add the enum field to your SaveObject, just like any other type.
@StickyVD
@StickyVD 4 жыл бұрын
As a beginner, I've been looking for ways to save and load, but I just cant understand how to save everything I need to save into one save file. Like, my scriptable object inventory has a save file, my player also has a save file, and my enemy spawner makes it so that each individual enemy it spawns makes a save file for each one! lol XD isn't there a way to just write all of these into one single json file?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Usually what I do is define a class for the master save that contains all the others. So my main SaveObject has { PlayerSaveObject, InventorySaveObject, StatsSaveObject } and so on
@StickyVD
@StickyVD 4 жыл бұрын
@@CodeMonkeyUnity hmmm that makes sense.. could you explain further? :)
@StickyVD
@StickyVD 4 жыл бұрын
@@CodeMonkeyUnity nvm, I got it XD thanks!!!!!
@TidaliCreative
@TidaliCreative Жыл бұрын
Is this up to date? Nice vid!
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
Yup, nothing here is dependent on any specific Unity/C# version
@TidaliCreative
@TidaliCreative Жыл бұрын
@@CodeMonkeyUnity okay cool, thx!
@TidaliCreative
@TidaliCreative Жыл бұрын
Would you personally use this in a single player game? And how would it work for multiplayer? I heard there is a package regarding multiplayer, do you have a tutorial on that? As always I'm very grateful for your content, keep it up!
@jesseramon5013
@jesseramon5013 3 жыл бұрын
6:26
@zhrgci
@zhrgci 4 жыл бұрын
As a beginner this is way too difficult :l
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
What did you find difficult?
@zhrgci
@zhrgci 4 жыл бұрын
@@CodeMonkeyUnity Nvm I was able to figure it out. The problem I had was just following, because you started with so much code but in the end I only had needed a small part. But thanks for asking
SAVE & LOAD SYSTEM in Unity
18:20
Brackeys
Рет қаралды 1,1 МЛН
Why You Should Always Help Others ❤️
00:40
Alan Chikin Chow
Рет қаралды 99 МЛН
Заметили?
00:11
Double Bubble
Рет қаралды 3,5 МЛН
ДЕНЬ РОЖДЕНИЯ БАБУШКИ #shorts
00:19
Паша Осадчий
Рет қаралды 7 МЛН
Сохранение игры в файл в Unity
20:13
Лавка Разработчика
Рет қаралды 15 М.
What are Events? (C# Basics)
15:05
Code Monkey
Рет қаралды 374 М.
How To Render 2 Million Objects At 120 FPS
14:57
Tarodev
Рет қаралды 136 М.
How to make a Save & Load System in Unity | 2022
26:56
Shaped by Rain Studios
Рет қаралды 175 М.
Better Save/Load using Data Binding in Unity
18:47
git-amend
Рет қаралды 10 М.
I also make MISTAKES!
7:29
Code Monkey
Рет қаралды 20 М.
What are Interfaces? (C# Basics)
13:54
Code Monkey
Рет қаралды 201 М.
How to Build A Save System in Unity
9:40
Game Dev Guide
Рет қаралды 170 М.
How To Create An Advanced Save System In Unity
16:00
Dapper Dino
Рет қаралды 31 М.
Why You Should Always Help Others ❤️
00:40
Alan Chikin Chow
Рет қаралды 99 МЛН