Persistent Data - How to save your game states and settings | Unite Now 2020

  Рет қаралды 79,257

Unity

Unity

Күн бұрын

Пікірлер: 131
@ian_snyder
@ian_snyder 4 жыл бұрын
These videos always come up right AFTER I spent days banging my head against an issue 😂 I like to tell myself I learned a lot in the process 😜
@MrFarkasOfficial
@MrFarkasOfficial 3 жыл бұрын
Hahaha ikr
@stesproject
@stesproject 4 жыл бұрын
I really needed a video like this 3 years ago, when I started using Unity. I remember I struggled a lot to build a save/load system for my game. After watching the video I'm happy to see I've done a good job. I developed a pretty similar system :)
@Bletzkarn
@Bletzkarn 4 жыл бұрын
One of the better tutorials I've seen on Unity channel. I think these generalised tutorials make for very strong content.
@raffaelechinotti5244
@raffaelechinotti5244 3 жыл бұрын
agreed
@gagang4286
@gagang4286 4 жыл бұрын
I was just finding the best ways to save my app data and then this video comes in. Looking forward to use Json to do so for now.
@Xenobicus
@Xenobicus 4 жыл бұрын
Great content covering the options and explanations/reasoning to help choose the correct route- Please keep making content like this.. and consider zooming in on the code for easier readability in the video for future tutorials. Thank you!
@512Squared
@512Squared 2 жыл бұрын
Really enjoyed your presentation, clarity and explanations. Really pulled all the stuff I've been reading and watching together. 👍🍻
@ZacharyAghaizu
@ZacharyAghaizu 3 жыл бұрын
great timing! was convinced to buy the easy save and it's nice
@dmitrypriadko4409
@dmitrypriadko4409 2 жыл бұрын
Just what I needed! Thanks! And the guy should not be so nervous) Great job!
@clarkmeyer7211
@clarkmeyer7211 3 жыл бұрын
players prefs is exactly self explanatory though. you use it for your preferences such as volume, sensitivity, keybinds etc. things that don't have any game breaking impact if edited.
@Gers217
@Gers217 4 жыл бұрын
I'm a simple man I saw Vscode and I give a like to the video
@aldigangster123
@aldigangster123 4 жыл бұрын
I really appreciate the effort and Saving / Serialization is definitely something Unity should put out more tutorials. But this one failed to deliver any knowledge imo. Even as someone with basic knowledge of JSON serialization, this was horrible to follow or understand. Long breaks without speech while silently commenting out code. No explanation of each function, or its lines. FileManager? I've seen much better explanations from random KZbinrs and would expect a lot more from Unity. Sorry if this is a bit harsh.
@nathanielguggenheim5522
@nathanielguggenheim5522 4 жыл бұрын
I would like to have mention the drawbacks. This does not work on spawned enemies. Everything saved must come with the scene. Also if the scene changes in case of a patch, this solution breaks. Consider a new enemy is in the patch. He will probably get the id of the enemy right after him and so on. All saved data on and after this enemy will be corrupted. And now imagine enemies with different data. Crash. As long as there is no way to produce an unique Id taking more information into account (e.g. spawn position, time, whatever) data cannot be reproduced in case anything changes (scene).
@stefan429
@stefan429 4 жыл бұрын
Very nice :) not many vids covering my preferred ways to save
@Ziplock9000
@Ziplock9000 4 жыл бұрын
4:40 If your registry is being corrupted, you have much bigger problems that saving to files won't fix.
@gegenton3953
@gegenton3953 4 жыл бұрын
I would appreciate more content on server side saving as in "actual implementation". JSON and PlayerPrefs are both relatively easy to understand while server side saving requires some more thinking ahead. Expecially mobile integration would be interesting, e. g. for offline states of the player. Thanks for that overview, though! Great presentation!
@gegenton3953
@gegenton3953 4 жыл бұрын
@@bronsonzgeb5651 Thanks for the detailed answer! I guess I'll have to have a look at the server docs more properly then ;) Was thinking about an off the shelf solution for android using the PlayStore built-in options, but maybe that doesn't even exist? At least now I have some starting points, thanks!
@gegenton3953
@gegenton3953 4 жыл бұрын
@@bronsonzgeb5651 I kinda am, yes. Just some simple systems that are cheat-proof. E. g. running a small game look (Tetris, Snake, etc.) locally but saving the (high-)score directly on the server. The score itself can savely be stored, I'm sure, but is it generated safely enough to prevent cheating? These kind of things currently grind my gears ;) Looking forward to more content of yours on persistent data, then :)
@gegenton3953
@gegenton3953 4 жыл бұрын
@@bronsonzgeb5651 Well, that's a great idea. In my special case I can think of some parameters right away ;) Thanks a ton!
@dryrunhd
@dryrunhd 2 жыл бұрын
Great video. So then in the scenario where we have a game and we're keeping important player data on a remote server, and we're heeding the advice of not trusting anything the game client says, what's the right way to do user auth such that they're reliably retrieving their own save data?
@coolkidllama1483
@coolkidllama1483 4 ай бұрын
this video is great, but i would like to see a video of someone using these things starting from a blank project and start with variable data, then go up the list. like a name and ID system that saves the stuff would be nice.
@KalechippsDev
@KalechippsDev 3 жыл бұрын
Awesome tutorial, practical and succinct. Thanks!
@512Squared
@512Squared 2 жыл бұрын
There are some complaints in this thread about things not being clear, of pieces missing - if you have any questions, just reply and I can answer them. I got this working just fine.
@beneuser1220
@beneuser1220 2 жыл бұрын
I have the problem, that I don't know how to set up the UUID for my enemies. How did you do that?
@512Squared
@512Squared 2 жыл бұрын
@@beneuser1220 attach this script to all your enemies: ​using​ ​UnityEngine​; ​[​ExecuteAlways​] ​public​ ​class​ ​GenerateGUID​ : ​MonoBehaviour ​{ ​ [​SerializeField​] ​ ​private​ ​string​ ​_gUID​ ​=​ ​"​"​; ​ ​public​ ​string​ ​GUID​ { ​get​ ​=>​ ​_gUID​; ​set​ ​=>​ ​_gUID​ ​=​ ​value​; } ​ ​private​ ​void​ ​OnValidate​() ​ { ​ ​//​ Only populate in the editor ​ ​if​ (​!​Application​.​IsPlaying​(​gameObject​)) ​ { ​ ​//​ Ensure the object has a guaranteed unique id ​ ​if​ (​_gUID​ ​==​ ​"​"​) ​ { ​ ​//​Assign GUID ​ ​_gUID​ ​=​ ​System​.​Guid​.​NewGuid​().​ToString​(); ​ } ​ } ​ }
@512Squared
@512Squared 2 жыл бұрын
@@beneuser1220 you can then set up a GUID string field in your main enemy class and retrieve the GUID by putting this in your Start: private string _enemyGuid; void Start() { _enemyGuid = GetComponent().GUID; }
@512Squared
@512Squared 2 жыл бұрын
@@beneuser1220 You can be call you GUID variable UUID if you want, makes no difference, idea is the same. GUID is generally understood to be Microsoft's implementation of UUID, though there can be subtle differences in GUID standard Vs RFC4122 UUID, but not anything you need to think about. Let me know if you got this working - you'll need to either call the Save and Load methods via Awake, Start or OnDestroy, or via UI buttons, depending on your preference and game style.
@512Squared
@512Squared 2 жыл бұрын
@@beneuser1220 Just remember that a prefab will be given the same GUID if you don't unpack it first. If you are instantiating via a prefab, you can assign the GUID at that point through script. I also use a button (Odin.Inspector) in the Inspector for resetting the GUID when I unpack the prefab. If you don't have Odin, you could create your own custom drawer for this - shouldn't be too difficult.
@page0809
@page0809 4 жыл бұрын
Awesome tutorial on save data! Thank you!
@XnecromungerX
@XnecromungerX 4 жыл бұрын
Thank you so much for making this video
@afrakes4510
@afrakes4510 3 жыл бұрын
a bit complicated for a noob. I wish you would have used a more clear cut example for the unityJson. It was helpful to get a good understanding of how it works, but im finding it difficult to apply it while learning to code. nicely done, just above my head. intermediate+
@salmanalsaffar8040
@salmanalsaffar8040 3 жыл бұрын
the problem with jsonutillty that if you updated a value in will update all the other values in the json file
@yudnai5577
@yudnai5577 3 жыл бұрын
how did you Create the Uuid? i see you use it in many places. did you build it by yourself or with unity build in class?
@vraios
@vraios 2 жыл бұрын
it's built-in C#. string guid = System.Guid.NewGuid().ToString(); (using System;)
@hungnong3760
@hungnong3760 3 жыл бұрын
thankiu this is what i need
@mrp0001
@mrp0001 4 жыл бұрын
Should have had timestamps
@mrp0001
@mrp0001 4 жыл бұрын
@@bronsonzgeb5651 oh, great!
@yudnai5577
@yudnai5577 3 жыл бұрын
Unity should buy easy save like they did with Bolt.!!! saving a lot of problems for people using the engine.
@donnewcomb3547
@donnewcomb3547 3 жыл бұрын
Thank you great video! question? how would you load Json data between scenes? I made a start menu, but as soon as I load my scene from, the menu I created, I receive compiler errors. however if I load the same data staring from the scene I'm trying to load, instead of the menu scene, it works perfectly??? I would appreciate some help upstanding this, but regardless. thank you for a wonderful tutorial
@RedstoneinventeArmoredGuy
@RedstoneinventeArmoredGuy 4 жыл бұрын
what is the LoadFromFile ? What data type is it? Cannot access it
@spotonmusic7554
@spotonmusic7554 4 жыл бұрын
What's inside the FileManager class? He didn't mention it.
@spotonmusic7554
@spotonmusic7554 4 жыл бұрын
@@bronsonzgeb5651 ok, thanks a lot.
@Talha-hg4sl
@Talha-hg4sl 3 жыл бұрын
How to save data on server load pls make a video on this or any guidance
@Gurem
@Gurem 3 жыл бұрын
How to save animation data so the player can load mid attack animation
@ooDEFENDERoo
@ooDEFENDERoo 4 жыл бұрын
Thank you so much!
@faiz7180
@faiz7180 3 жыл бұрын
How to save the data after adding new features to my game? Like when users download an update from playstore and then keep users old data. Is the method shown in this video work?
@Ziplock9000
@Ziplock9000 4 жыл бұрын
JSON compact? It's an ASCII or Unicode representation of simple types that uses a lot more space
@Paanch_Tanmatra_Studio
@Paanch_Tanmatra_Studio 3 жыл бұрын
Amazing tutorial. I also have a save system playlist series. It covers from player-pref to Firebase. I am currently editing the video with NodeJS as the back-end server for saving data. Any feedback on it will be really helpful.
@StarkTech47
@StarkTech47 3 жыл бұрын
Very strong save system, it's a pleasure to follow the different steps but for the Uuid, how did you do to make them persistent. I have been working on it for many days and I don't find a way to do it.
@cydu
@cydu 2 жыл бұрын
Error with Path and File does not exist in the current content
@mintydog06
@mintydog06 4 жыл бұрын
Maybe it's just me, but I couldn't really follow the JSON example. I can't see what files/classes you are looking at and how they are connected.
@Gmania999
@Gmania999 4 жыл бұрын
Please tell me the name of your color theme (VS), looks nice to my eyes. By the way, why not store data at the binary level? Using Protobuf.Serialize() ? like a [ProtoBuf.ProtoContract] public struct Data { [ProtoBuf.ProtoMember(1)] public string UUID; [ProtoBuf.ProtoMember(2)] public int M_Data1; [ProtoBuf.ProtoMember(3)] public int M_Data2; } This will improve the performance of the game, you can also put the UUID in the file name.
@Gmania999
@Gmania999 4 жыл бұрын
@@bronsonzgeb5651 Thanks!
@simpson6700
@simpson6700 3 жыл бұрын
i just want to know how to change the save location... as a player i hate it when games save in appdata.
@gilleswalther5964
@gilleswalther5964 4 жыл бұрын
Very helpful thanks
@oliverwigren163
@oliverwigren163 3 жыл бұрын
how do you access/find the savedata.dat file on mac?
@alex_steed8472
@alex_steed8472 4 жыл бұрын
Is there any advantages to using sqllite? I have lots of data. Mostly structured.
@pt8306
@pt8306 4 жыл бұрын
JSON is a tree structure, SQL is a flat table structure. If your data is more tabular in nature (like how some RPGs have a lot of flat tables for things like XP gains), you might have an easier time using sqlite. If you want objects to take care of themselves, JSON can easily store all their information in the same structure as your C# class, which is very nice. If you instead want a very centralised data model where everything needs to have lightning-fast access to a centralised data store, sqlite is the way to go.
@jamescampbell1622
@jamescampbell1622 2 жыл бұрын
To understand this tutorial, you must already know 90% of what he's attempting to explain. Does not write or explain why or how most things work. Shows snippets of code with no references on what makes them work. Hopefully this helps the more advanced pupils.
@WinchD
@WinchD 4 жыл бұрын
what about using scriptable objects for saving game data?
@nathanielguggenheim5522
@nathanielguggenheim5522 4 жыл бұрын
As far as I've read, there is no way to produce an unique Id. So you can also just register all enemies in a list in Awake() and save this list. If an enemy was Destroyed, the list entry is null, so you save a 'Destroyed' information for that index. So your uuID saves no purpose. But both solutions cannot handle spawned enemies. All you can save here must come with the scene. Any ideas of how to address this problem?
@divyanthj
@divyanthj 4 жыл бұрын
Where is FileManager? where do I import it from?
@albertmontagutcasero2129
@albertmontagutcasero2129 4 жыл бұрын
FileManager of the video is a class that the teacher has coded. He explains how at min 17:27. It is not from the engine namespaces.
@albertmontagutcasero2129
@albertmontagutcasero2129 4 жыл бұрын
@@bronsonzgeb5651 Thank you for requesting the links, for sure it will be helpful! Congratz on the video!
@greggalloway6410
@greggalloway6410 3 жыл бұрын
Was this edited to cut out the time Unity is saving/reloadind when hitting play? I'm just wondering if I'm missing a setting that'll save me hours of my life.
@duckriddle3340
@duckriddle3340 6 ай бұрын
Both asset store links leads to Easy Save :(
@pt8306
@pt8306 4 жыл бұрын
How am I supposed to give every savable object in my game a UUID that is always the same every time the game is loaded? I can't just assign a UUID in the constructor and I don't want to have to assign it one in the inspector. They need to have a consistent UUID so when I save/load their data it's associated with the correct entity.
@saniel2748
@saniel2748 4 жыл бұрын
You could do [SerializeField] string uuid = System.Guid.NewGuid().ToString(); in class as default value, so every time it'll set new guid, which is not likely to overlap. I did it myself, seems to work
@pt8306
@pt8306 4 жыл бұрын
@@saniel2748 I guess. Can I use [HideInInspector] too since I don't want it to be seen by my artists?
@saniel2748
@saniel2748 4 жыл бұрын
@@pt8306 i would recommend making your own attribute because HideInInspector is not visible even in debug view But technically yes, you can
@pt8306
@pt8306 4 жыл бұрын
@@saniel2748 how can I detect debug mode in my editor script?
@saniel2748
@saniel2748 4 жыл бұрын
@@pt8306 I mean switching the inspector to debug view
@sillysillygoosgoos
@sillysillygoosgoos 2 жыл бұрын
Nice content.
@evenprime1658
@evenprime1658 3 жыл бұрын
so i use json to save data but i made a encryption system to encrypt the keys using some sketchy algorithm imade.. is it safe or is it easily reversable because its json
@donkeykong315
@donkeykong315 Жыл бұрын
Any data on a player's computer should be considered as accessible/modifiable by the player.
@joaohudsonlacerdaoliveira5253
@joaohudsonlacerdaoliveira5253 4 жыл бұрын
Wouldn't serializing in binary be another good option?
@duramirez
@duramirez 2 жыл бұрын
É basicamente o que eu faço, criei uma biblioteca minha mesmo que salva tudo em uma cadeia de bytes organizados hehehe Consome muito menos espaço em disco porque não tem overhead né.
@ohj6878
@ohj6878 2 жыл бұрын
What is "FileManager" please its doesn't exist and callback an error
@vraios
@vraios 2 жыл бұрын
this tutorial is weirdly cut but what you want is in 17:30 and 17:55. just create new class FileManager and add these 2 methods
@ohj6878
@ohj6878 2 жыл бұрын
@@vraios thx but still some value that are unsigned even in this class .. "Path" and "File" in 17,30 doesn't exist
@cydu
@cydu 2 жыл бұрын
@@ohj6878 Same error
@MohammadFaizanKhanJ
@MohammadFaizanKhanJ 4 жыл бұрын
I was thinking playerprefs save data into file in data folder of the build.
@ThatRazzy
@ThatRazzy 2 жыл бұрын
Does anyone know how to delete the JSON save data upon starting a new game?
@donkeykong315
@donkeykong315 Жыл бұрын
You could just save an empty file on the same filepath.
@GUYX10
@GUYX10 2 жыл бұрын
found this very unclear. basicly what i got from this tutorial was "copy paste my code dont worry how to works".
@gokayakcay7093
@gokayakcay7093 4 жыл бұрын
Am I the only one who don't have filemanager in Unity ??
@QvsTheWorld
@QvsTheWorld 3 жыл бұрын
It's a custom class with 2 static methods, WriteToFile and LoadFromFile. He starts his explanation at 17:25 . Here is what it looks like. public class FileManager { public static bool WriteToFile(string a_filename, string a_filecontent) { var fullPath = Path.Combine(Application.persistentDataPath, a_filename); try { File.WriteAllText(fullPath, a_filecontent); return true; } catch (Exception e) { Debug.LogError("Fail to write to " + fullPath + " exception:" + e); } return false; } public static bool LoadFromFile(string a_filename, out string result) { var fullPath = Path.Combine(Application.persistentDataPath, a_filename); try { result = File.ReadAllText(fullPath); return true; } catch (Exception e) { Debug.LogError("Fail to read from " + fullPath + " exception:" + e); result = ""; return false; } } }
@carrotcat5940
@carrotcat5940 2 жыл бұрын
@@QvsTheWorld hippity hoppety that code is now my property
@mjaada
@mjaada 4 жыл бұрын
or another alternative on lootboxes, don't add them at all!
@insidiousmaximus
@insidiousmaximus 3 жыл бұрын
this is some kind of spaghetti tutorial so many things not explained uncommenting all this code from earlier, no mention of interfaces, gameviewconroller etc, you dont teach people like that, you demonstrate with the most simple example to outline the flow. Then build complexity on top of that. This is a mess.
@ElDonitazz
@ElDonitazz 3 жыл бұрын
I'll be the one making Unity related videos yelling, rainbows and explosions. Mark that down.
@ayan3789
@ayan3789 4 жыл бұрын
Unity please make tutorials for ragdolls!
@pt8306
@pt8306 4 жыл бұрын
Turn off IsKinematic on your model, make sure it has a rigidbody. Ragdolls should work fine
@ayan3789
@ayan3789 4 жыл бұрын
@@pt8306 ragdoll movement?
@pt8306
@pt8306 4 жыл бұрын
Why is your ragdoll moving?
@ayan3789
@ayan3789 4 жыл бұрын
@@pt8306 ragdoll movement and balance scripts, i cant find any good tutorials
@pt8306
@pt8306 4 жыл бұрын
@@ayan3789 Normally you don't want to balance ragdolls. Instead you want to set them to kinematic movement and control them directly (with no physics), then "trigger" ragdolling by letting the rigidbody take over
@IronFreee
@IronFreee 4 жыл бұрын
Player Prefs is really dirty in windows, it will write data in the registry. Just make a Json (or XML) in any case. Why dictionary can't be serialized? For Assets (Item sprites...), the best way to do it is to put them in the "Resources" folder and name them with an ID system. Then check if they exist when loading your data to avoid error. It's very error prone, but it's easy and Unity offers no solution.
@IronFreee
@IronFreee 4 жыл бұрын
@@bronsonzgeb5651 Thank you for the tip, I will try that. It sound good :D (Will be easier to maintain)
@trod146
@trod146 4 жыл бұрын
Why do so many people from Unity whisper at points in these videos?...
@brunopinheirobrazil5352
@brunopinheirobrazil5352 4 жыл бұрын
Is it okay for us to only use PlayerPrefs to save data? Or we could lose it somehow?
@mrp0001
@mrp0001 4 жыл бұрын
It's not really good, involves a lot of strings and has other issues.
@evilmind5178
@evilmind5178 3 жыл бұрын
So you still use hungarian notation.... well.
@ohj6878
@ohj6878 2 жыл бұрын
the guy who did the same tuto in 2014 was far far better than this one this tuto is bad he do anything only show an already filled game its bad
@Athomield3D
@Athomield3D 4 жыл бұрын
Binaryformatter (ie binary files) work for me
@duramirez
@duramirez 2 жыл бұрын
I don't know if you are eating something or if it's gum, but it is super annoying and distracting. >_
@junpinox1574
@junpinox1574 3 жыл бұрын
honestly couldnt finish the video. 7 minutes in and there was just too much smacking/swallowing/mouth noises.
@eysn
@eysn 3 жыл бұрын
That mouth ASMR is really distracting when you have good headphones. Edit: 7 minutes in and I'm clawing at my face.
@vaultt309
@vaultt309 2 жыл бұрын
This is deadAss some "draw the rest of the owl" bullshit
@_g_r_m_
@_g_r_m_ 3 жыл бұрын
that's probably one of the worst tutorials ever made
@ThomLaurent
@ThomLaurent 4 жыл бұрын
With the length of the video I hope I would have learned something. It could be shrinked down to 10 minutes with montage or maybe 5 minutes if rushed.
@marshallwyatterb
@marshallwyatterb Жыл бұрын
this was a very poor tutorial. someone should redo this using the actual example files
@Lurkness
@Lurkness 3 жыл бұрын
Horrific tutorial, find another video. Uncommenting out code surrounded by unrelated functions looks bad. Hearing every small sound and keystroke is bad. What really blows me away is you make a reference to custom code, and explain it AT THE END OF THE SECTION. I don't think there's a nice way to put how inept that is. You breeze right past introducing FileManager to the extent I rewatched this thing from the start a few times to see if you included it, instead it was 17 minutes in. Random comments had to point this out. Please delist this, it should not be a top result from google.
@Lurkness
@Lurkness 4 ай бұрын
Update. This awful developer no longer works at unity and went on to make the most beginner game I've ever seen. No wonder this engine and company fell through, this guy was making their tools.
How to make a Save & Load System in Unity
26:56
Shaped by Rain Studios
Рет қаралды 212 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
Better Save/Load using Data Binding in Unity
18:47
git-amend
Рет қаралды 19 М.
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 804 М.
SAVE & LOAD SYSTEM in Unity
18:20
Brackeys
Рет қаралды 1,1 МЛН
The Ultimate Introduction to Scriptable Objects in Unity
20:45
Unity async / await: Coroutine's Hot Sister [C# & Unity]
16:18
Be CAREFUL with Scriptable Objects!
8:27
Code Monkey
Рет қаралды 88 М.
Easy Serialization and Encryption (Save games in Unity/Unreal)
38:58
Matthew Ventures
Рет қаралды 5 М.
How To Create An Advanced Save System In Unity
16:00
Dapper Dino
Рет қаралды 32 М.
How do non-euclidean games work? | Bitwise
14:19
DigiDigger
Рет қаралды 2,5 МЛН