How to Implement Save Slots to Manage Multiple Saved Games in Unity | 2022 tutorial

  Рет қаралды 29,173

Shaped by Rain Studios

Shaped by Rain Studios

Күн бұрын

In this video, I show how to implement Save Slots to manage multiple saved games by expanding on the Save & Load System created through two previous tutorials.
In this tutorial we'll cover how to organize multiple saved games, how to create a save slots menu, and also how to continue directly from the most recently played saved game.
Thank you for watching and I hope the video was helpful! 🙂
► SAVE & LOAD SYSTEM TUTORIAL PLAYLIST
The full Save & Load System tutorial playlist that this video is part of can be found here.
• How to make a Save & L...
► TIMESTAMPS
0:00 Intro
0:57 How it's going to work
3:23 Project Overview
4:19 Persisting Multiple Save Files
6:20 Getting all Profile Data at once
9:19 Creating the Save Slots Menu
11:44 Displaying Data for a Save Slot
16:51 Setting up Menu Navigation
18:49 Setting the First Selected Button
20:42 Starting a New Game through the Save Slot
23:32 Turning the Save Slot into a Prefab
24:03 Creating Multiple Save Slots
24:46 Loading from a Save Slot
27:12 Selecting the correct Save Slot when Loading
28:06 Disabling the Load Game Button
28:28 Defaulting to the most recently saved game
32:39 Debugging Options
34:20 Outro
► GITHUB PROJECT
The '3-load-across-scenes-implemented' branch is the starting point of the project for this tutorial and the '4-save-slots-implemented' branch is the end result.
github.com/shapedbyrainstudio...
► MUSIC
The backing music is custom made by @themaykit.
/ themaykit
► DISCORD
Come ask questions, suggest a video topic, or just hang out!
📱Discord ➔ / discord
► THE PATH OF REN
Wishlist 'The Path of Ren' on Steam!
🎮 Steam (The Path of Ren) ➔ store.steampowered.com/app/16...
► SOCIAL MEDIA LINKS
Follow my current project!
🐦 Twitter ➔ / trevermock
📷 Instagram ➔ / trevermock
🕑 TikTok ➔ / shapedbyrainstudios
🌐 Website ➔ shapedbyrainstudios.com/
► SUPPORT
Any support is much appreciated! I may receive a commission on any assets purchased using the below Unity Asset Store link.
🛍️ Unity Asset Store Affiliate Link ➔ assetstore.unity.com/?aid=110...
☕ Buy me a coffee! (Ko-fi) ➔ ko-fi.com/shapedbyrainstudios
#gamedev #unity2d #unity

Пікірлер: 68
@ShapedByRainStudios
@ShapedByRainStudios 2 жыл бұрын
Feel free to come by my Discord server and ask questions, suggest a video topic, or just hang out! ➔ 📱discord.gg/99gcnaHFf9
@xxhungover
@xxhungover 2 ай бұрын
this man could read my mind! Whenever I wonder about something, he mentions it immediately.
@inxendere
@inxendere Жыл бұрын
I literally love you. You have the most comprehensive tutorial for full save system in unity on all of youtube. Bless your soul.
@ShapedByRainStudios
@ShapedByRainStudios Жыл бұрын
Thank you for the kind words and really glad to hear the tutorial helped! 🙂
@Katubug
@Katubug Жыл бұрын
Thank you so incredibly much for making these. They have been unbelievably helpful! I think it really says something that my sister, who is a professional programmer, spoke praises of these videos - and yet me, a complete noob who started learning Unity/C# a month ago, can still understand, follow, and troubleshoot thanks to that same guide. Amazing work, and thanks to everyone in the comments and the discord who helped pitch in!
@tiagotozo811
@tiagotozo811 Ай бұрын
You sir are a legend. Thanks!
@Blu3zStudios
@Blu3zStudios 9 ай бұрын
Really is a masterpiece of a tutorial that I wish was more known to the people who struggle to do so. Just because it's a long series and a lot of information doesn't mean it should be skipped on. I made quite a research and this is by far the best save/load system tutorial I've encountered, which really helps in my projects and gamedevs ! So I really appreciate your hard work man.
@ShapedByRainStudios
@ShapedByRainStudios 9 ай бұрын
Thanks so much for the kind words! That means a lot and I'm really glad to hear the series was helpful to you!
@pawonator4854
@pawonator4854 Ай бұрын
Did it Awesome job with this tutorial, i really like how you explain even the more complicated stuff and how you are thinking on future debugging and improving your system 10/10
@shanceryt
@shanceryt 2 жыл бұрын
I sepnd 8 hours to follow along, because I wanted to learn it step by step. Nicely done tutorial!! Thanks for sharing, i definitely keep subscribed, you earned it!!
@ShapedByRainStudios
@ShapedByRainStudios 2 жыл бұрын
Thanks so much for the kind words! I'm really glad you found it to be helpful! 🙂
@TheAndyW19
@TheAndyW19 2 жыл бұрын
Just completed the 3 videos, very good series. Spent a while looking for a good approach for a save/load system. Lots of older Unity save systems use the binary formatter which I didn't want to use due to security vulnerabilities. Was looking for something using JSON that would be easy to edit but also have the ability for some basic level of encryption to avoid players modifying their data. This series was perfect for this. In my game I want to segment my data further however with some data being global such as the total number of player deaths. While other data is local to a certain scene / level such as the status of checkpoints or coins in a level. Should be easy enough to add this to your system. Keep up the great work.
@ShapedByRainStudios
@ShapedByRainStudios 2 жыл бұрын
Thank you so much for the kind words and thoughtful comment! I'm really glad you found the series useful (one more video to come for polish/bug fixes)! Best of luck! 🙂
@r.sp.378
@r.sp.378 Жыл бұрын
Thanks so much for makin these free. Insane helpfull for the making of my game.
@wing2s
@wing2s Жыл бұрын
Elegant and clean solution.
@yorkipudd1728
@yorkipudd1728 2 жыл бұрын
Saved and subbed. Thank you.
@joaocarlosp.p.6550
@joaocarlosp.p.6550 Жыл бұрын
Thank you! Greate Tutorial!
@randyleerandyleerandylee
@randyleerandyleerandylee 2 жыл бұрын
thank you for making this series.
@ShapedByRainStudios
@ShapedByRainStudios 2 жыл бұрын
You're welcome! I'm really glad that people are finding it useful! 🙂
@burgundyboysyt2272
@burgundyboysyt2272 11 ай бұрын
Thank you so much for this
@gidrar5372
@gidrar5372 2 жыл бұрын
Hello! I don't miss one of your videos
@ShapedByRainStudios
@ShapedByRainStudios 2 жыл бұрын
Right on! That means a lot and I hope you're finding them to be helpful! 🙂
@piobug
@piobug Жыл бұрын
Thanks!
@wagnercastro7399
@wagnercastro7399 Жыл бұрын
To select a button in the new activated menu you just need to create a variable of the type button for the button you want and use the select command [SerializeField]Button btn; btn.Select();
@jnarcher
@jnarcher 5 ай бұрын
Thanks! Super easy solution
@thenubblet3925
@thenubblet3925 Жыл бұрын
great series i really learned a lot from this thanks :) I just had one question you have a position variable for the player in GameData do you need to make a new variable in GameData if you also want to save the position of something in a different class to the player or dose each class that inherits from IdataPersitance have it own version of GameData so you can reuse the position variable for everything you want to save the position of
@jazmeister
@jazmeister Жыл бұрын
god you are amazing
@RomaHoma7
@RomaHoma7 10 ай бұрын
Would it be possible to make a ui system in which that main menu doesn’t have a continue and a new game buttons but instead just has a play button. and if this button is clicked it would open a menu where if an existing game is clicked it opens it with the saved progress and if an empty game is clicked it starts and saves the new game?
@muezz8667
@muezz8667 Жыл бұрын
Hello! just want to share something. Regarding the highlighted back button when no save data, I found issue where it highlighted the back button instead of EMPTY button even when clicking NEW GAME. What I did (I don't know how it works, but it works) I change "if (firstSelected.Equals(backButton.gameObject))" to "if (firstSelected == backButton.gameObject)". I hope it help for those encountering the same issue as mine.
@reglan_dev
@reglan_dev Жыл бұрын
can you make tutorial on how to add Naming worlds, and deleting them as well?
@BenGodot
@BenGodot Жыл бұрын
This!
@reglan_dev
@reglan_dev Жыл бұрын
@@BenGodot he made a tutorial on deleting worlds, yet not on naming them
@BenGodot
@BenGodot Жыл бұрын
@@reglan_dev Can maybe adapt the code?
@BrandonNyman
@BrandonNyman 8 ай бұрын
I am using this a bit differently. In my case, I am having multiple player profiles and saving them. Each profile just has a name and a customisable icon. They don't need an individual save slot system like this but each save their own data. Essentially unlimited profiles can be created by pressing a create profile button which needs to then create a profile button with the chosen icon and name text. Then loading the profile will load a bunch of data to change the stats in the scene. My main question here is, what is the best way to go about being able to dynamically create new profile slots at runtime with unique ids, save those and be able to instantiate a prefab containing a button with the script containing the profile id value and load profile data method, an icon holding a sprite image and text? Thank you very much for this series. It is the most comprehensive ive found after a ton of research and far better than anything I could have come up with on my own. Its so well explained with almost everything considered and easily adaptable too. This is my second time using it actually but for a totally different project. Edit: I can confirm it worked perfectly in my use case. A bit finicky to begin with but once I got it working it does exactly what I was looking for.
@reynielmahinay7028
@reynielmahinay7028 Жыл бұрын
Hi! how to know if there is a data in save slot and if there is no data load the 1st scene. if there is a data load the last scene where the player is. this part is the SaveGameAndLoadScene because i have multiple scene
@842p
@842p 7 ай бұрын
So one problem that I have is I have a coin system like yours, where you can pick up coins that you get from destroying stuff, and then updating some text. But, I'm having some trouble with setting my current gold count equal to my data.coinsCollected from the LoadData/SaveData functions I have set up. Any way to fix this?
@danielprietohuguenin5588
@danielprietohuguenin5588 Жыл бұрын
This is amazing, I have a question though, I changed the save system to save the scene im in but when i change scene the data doesnt load unless I saved it before, but when i do that it also saves the location, is there a way to only save the death counter when changing scene and loading it again in the new one without saving the position?
@ShapedByRainStudios
@ShapedByRainStudios Жыл бұрын
Hey there and thank you for the kind words! 🙂 There are a couple options I would recommend here, but it completely depends on your game. 1. Separate out any scene specific data (like the player position) into it's own Serializable class that maps to the scene it corresponds to. Something like a 'SceneData' class. Or in other words, you'd save and load a different player position for each scene. From there, you can keep data that spreads across the scenes at the top level so that it carries over throughout all of them. It sounds like this should solve your issue and I recommend this approach over option #2, but if this doesn't seem like it would work for your game then take a look at my next suggestion. If this solution is confusing, I suggest reading up on a topic called 'Object Oriented Programming' (OOP) if you're not familiar - which should help you understand different ways your data can be organized. 2. Instead of using the IDataPersistence interface to save data, only use it to load the game. For saving, allow the scripts to directly push data to your gameData variable. In other words, for saving data in this tutorial we're going in this direction: DataPersistenceManager -> IDataPersistence Script; however, you'd be changing it to go in the other direction instead: Any Script -> DataPersistenceManager. With it going that direction, your script gets to choose when to save data instead of the DataPersistenceManager. By doing that, you'd be able to save portions of the data rather than the entire thing at once. **With that said** - option #2 does have some downsides. By allowing scripts to directly modify the gameData at any time, it becomes harder to track what's going on within the system and may make troubleshooting much harder down the line. It also introduces somewhat of a circular dependency between your scripts and the DataPersistenceManager which is generally good thing to avoid. I think option #2 will work fine for a smaller game, but it's good to keep the downsides in mind regardless. TL;DR - go with option #1 unless for some reason that won't work for your game. I know that's a bunch of info above, but hopefully it makes sense. It'll likely take some time and playing around with the system to fully grasp how you need to go about it. Best of luck to you!
@Apfel_56
@Apfel_56 5 ай бұрын
Hello. I know I'm here late, but I'm going to ask anyway. I've been following the save and load series, and for some reason I'm still having problems with the system. The saving process itself works (the data is saved to a file), but when I try to load the data back, the chance that it will actually do the job is 50/50, otherwise it initializes a new game. What could I have done wrong?
@mysticowlgames
@mysticowlgames 7 ай бұрын
I am facing an issue where, if I go from the New game to save slots, I can use the input system to navigate, but if I go back, I can't. Please Help!
@ImaginatorPage
@ImaginatorPage Жыл бұрын
Hey there Trever, amazing video as always! The majority of my game's data which I want to persist, however, are variables created and modified in Ink files, and they carry over between save slots! Is there a way to make the ink variables be separate to each of the save slots, just like the player's position, instead of being applied to all of them? I was testing my game if I create a new save slot, obtain progress through dialogues (ink variables), exit the game and create a new save slot, the ink data will still be there 😥 even if I delete the save slot... If you have any hints on how to avoid this, I'll really appreciate it!
@ShapedByRainStudios
@ShapedByRainStudios Жыл бұрын
Hey there and thank you for the kind words! 🙂 Since the saved data in this system is done for completely separate files - as long as you're saving that Ink variable data in the file corresponding to that save slot it shouldn't interfere at all with other save slots. I imagine you went through my Ink+Unity tutorials though, where in one of the videos we used PlayerPrefs to "save/load" the Ink Variable data. My est guess is that your issue has to do with that - since PlayerPrefs has no knowledge of the Save Slots and will carry across all of them. Assuming that's the case, what you'll want to do is save/load the Ink vaiable state using the Save & Load System from these videos instead of using PlayerPrefs like shown in that other tutorial. After making that switch, your Ink variable state should be separated by the Save Slots as you'd expect. I actually have a FAQ post on my Discord (see video description for the link) for integrating together the Save&Load and Dialogue System tutorials. It's not a full-on step-by-step solution, but it's pretty close and should at least give you enough info to get started with it. Be sure to check that out if you need a bit more guidance. I hope that helps and best of luck!
@ImaginatorPage
@ImaginatorPage Жыл бұрын
@@ShapedByRainStudios Many thanks! Yeah I've been following all your tutorials since the first one, so the ink data is being saved in the PlayerPrefs. But that part was done many months ago, so I don't even remember how to change this setting anymore 😅 I'll definitely check the Discord FAQ out!
@ImaginatorPage
@ImaginatorPage Жыл бұрын
@@ShapedByRainStudios So I followed the FAQ on Discord and it actually worked!! Thank you so much, you're literally a hero!
@salad1963
@salad1963 Жыл бұрын
Hi, when clicking an empty save slot, i get this error "NullReferenceException: Object reference not set to an instance of an object DataPersistenceManager.SaveGame ()" I followed everything in this video and even copied the code as I thought mine was causing the error. Would really appreciate if anyone has a fix for this. Thank you!
@001Andromeda
@001Andromeda Жыл бұрын
This will work on mobile devices?
@unknownpe4r
@unknownpe4r 2 жыл бұрын
Hi , I ran into an issue that I can't seem to figure out a solution, in the SaveSlotsMenu script theres the scene load section, the problem is that it's fixed to only one scene only so it'll always load that pre defined scene, I was wondering how can I start off my game from another scene that my player entered (my game will have various for each section). When my player loads a new scene and exits the game, when I load it back up the player position is in the same spot but way off in another part of that first scene that was defined in code
@ShapedByRainStudios
@ShapedByRainStudios 2 жыл бұрын
For anyone reading this in the future - we resolved this on Discord. But in short - you'll want to save the last scene that the player left off on by adding that to your GameData. Then, you can load and reference that value when you load the gameplay scene from your main menu (instead of hard coding it like I do in this tutorial). The thread (with a stubbed out code example) is available on my Discord server in a FAQ channel called _#loading__-the-most-recent-scene_ for anyone who would like to see a step-by-step solution regarding this. Best of luck! 🙂
@TheGrimmy
@TheGrimmy Жыл бұрын
This was really well done, but I feel like I missed a couple things. My NewGame() from DataPersistenceManager doesn't actually make a new game, it just loads the saved game. This is a problem I had even before this video, that I couldn't find a solution to. Also, my new or load menu doesn't reflect the simple "moneyText.text = gameData.money.ToString();" As if the GameData script file isn't quite working... despite it being able to save and load accordingly. Which is why I've been confused as to how to fix those other two issues. Any ideas on what could be causing those?
@ShapedByRainStudios
@ShapedByRainStudios Жыл бұрын
Hey there and thank you for the kind words! It's tough to recommend anything specific given the issues you're having, but here are my initial thoughts that should hopefully help a bit. For your NewGame() not making a new game issue - this might be related to an issue with the sceneUnloaded event that I talk about in this video (see the Removing the sceneUnloaded event timestamp) - kzbin.info/www/bejne/r4W6gZafoqaXrLs&t . In short, since NewGame() is just setting new data locally, that new data needs to be saved to the file as well or else it'll just get overwritten by the previously saved data when the game loads. I believe that timestamp in the other video should cover the fix for that by adding SaveGame() before scene transitions. For your other issue, I unfortunately don't have any solid recommendations without being able to see your project. It's possible the first issue you're having is related, so I would focus on fixing that one first and then moving on to this one after. If all else fails, be sure to check against the code on Github as well. It's really easy to miss stuff when going through the video. Here's a direct link to the scripts at the end of this Save & Load series - github.com/trevermock/save-load-system/tree/5-bug-fixes-and-polish/Assets/Scripts I hope you're able to get things working! Best of luck! 🙂
@TheGrimmy
@TheGrimmy Жыл бұрын
@@ShapedByRainStudios Thank you so much for getting back to me. I've been going through the bugs and fixes video. About to finish it today. I did incorporate the saves fix earlier with not much luck, but I will definitely look over the scripts. I do have a more seasoned eye now especially with how you re-explain things in the fixes video there. This is a darn good series though, and I know it's probably some dumb oversight on my part. This was incorporated into an already mostly done menu and scenes system so that's probably why. I know how tough it is to reply to someone being like "Plz, is broken. help." so thank you so much for reaching out :D
@TheGrimmy
@TheGrimmy Жыл бұрын
@@ShapedByRainStudios I ended up calling DataPersistenceManager.Instance.DeleteProfileData(saveSlot.GetProfileId()); in the SaveSlotsMenu when a new game overwrite is confirmed. This deleted the already there saved game, created a new one where in the appropriate slot, and has everything else including backing up and loaded backup save files working. That fixed it, and gameData can go suck a *bleep*. Thanks again in trying to help. Best wishes and hopes in your upcoming challenges :D
@Pedro_Marangon
@Pedro_Marangon 2 жыл бұрын
19:30 that's weird, normally I just set directly the UI option with EventSystem.current.SetSelectedGameObject(object) (for example, in the ActivateMenu() from SaveSlotMenu, I would do EventSystem.current.SetSelectedGameObject(saveSlots[0])
@ShapedByRainStudios
@ShapedByRainStudios 2 жыл бұрын
Oh interesting. And that doesn't give you a highlighting issue at all (like it doesn't highlight it properly)? I wonder if maybe it's a Unity version difference or something. I'll definitely play around with that a bit more because doing it that Coroutine way is a pain! Thanks for giving some input on this! 🙂
@Pedro_Marangon
@Pedro_Marangon 2 жыл бұрын
@@ShapedByRainStudios Never got an issue with it
@Pedro_Marangon
@Pedro_Marangon 2 жыл бұрын
@@ShapedByRainStudios Also another way I do it is by calling the Select() function directly from the OnClick event of the button (i.e. I set the new selected button as the object and call Button.Select(), just like how you call a method from a script). I also use this with the SetActive() methods, without needing to create a script for that
@ShapedByRainStudios
@ShapedByRainStudios 2 жыл бұрын
@@Pedro_Marangon Thank you for sharing how you're going about it! I'm sure this info will help some others who are following this tutorial clean that section up! 🙂
@322ss
@322ss 2 жыл бұрын
@@ShapedByRainStudios I've got the same results as Pedro - SetSelectedGameObject and Select both work just fine from Start or in an if in Update. I tried this in 2022.1
@Thothanos
@Thothanos Жыл бұрын
Where can I download codes?
@heattik
@heattik Жыл бұрын
Please help... The object of type 'Hero' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.
@ShapedByRainStudios
@ShapedByRainStudios Жыл бұрын
Hey there! It looks like you found your way to the Bug Fixes video (and other videos in the series) which I believe addresses this. 🙂 For others who come across this same issue though - this usually has been caused by trying to call SaveGame() in the DataPersistenceManager without first starting a NewGame() or calling LoadGame() with saved data - in which case the gameData is null. A good quality of life change for this is to check if data is null in SaveGame() and then (1) do some warning logging to let yourself know that SaveGame() was called with null data and then (2) return right away so it doesn't attempt to Save null data. This check is actually added in one of the following videos of this series. So TL;DR - in your workflow, make sure you call NewGame() OR LoadGame() with saved data before calling SaveGame(). I hope that helps!
@heattik
@heattik Жыл бұрын
@@ShapedByRainStudios Thank you so much
@hangry_demure
@hangry_demure 6 ай бұрын
🦸
@322ss
@322ss 2 жыл бұрын
Thanks for the videos. Could you consider dropping the hideous music loop? IMO it makes listening to your voice torture.
@ShapedByRainStudios
@ShapedByRainStudios 2 жыл бұрын
You're welcome! I don't plan on dropping the music loop anytime soon as I've gotten mostly positive feedback regarding it. To each is there own though and I can't please everyone. I'm glad you found the tutorial itself helpful at least!
@322ss
@322ss 2 жыл бұрын
@@ShapedByRainStudios I did find your videos useful, not trying to offend! Simply my honest opinion.
Чай будешь? #чайбудешь
00:14
ПАРОДИИ НА ИЗВЕСТНЫЕ ТРЕКИ
Рет қаралды 2,8 МЛН
How to make a Save & Load System in Unity | 2022
26:56
Shaped by Rain Studios
Рет қаралды 175 М.
Unity C# Saving and Loading Tutorial
27:25
GameDevHQ
Рет қаралды 26 М.
How to Build A Save System in Unity
9:40
Game Dev Guide
Рет қаралды 170 М.
How to make a Dialogue System with Choices in Unity2D | Unity + Ink tutorial
29:45
Shaped by Rain Studios
Рет қаралды 133 М.
How to Create Dialogue Audio like in Celeste and Animal Crossing using Unity
29:39
Making a Save & Load System in Unity using JSON
8:53
ChrisDev
Рет қаралды 6 М.
Sprinting with More and More Money
0:29
MrBeast
Рет қаралды 171 МЛН
PINK STEERING STEERING CAR
0:31
Levsob
Рет қаралды 18 МЛН
Это прекрасно🤯
0:27
Бутылочка
Рет қаралды 2,1 МЛН