Save & Load System in Unity - Bug Fixes, Scriptable Objects, Deleting Data, Backup Files, and More

Поділитися
Вставка
  • Опубліковано 2 лип 2024
  • This video wraps up the previous Save & Load System tutorials I've done by fixing some bugs, answering some frequently asked questions, and adding some extra polish and reliability to the system.
    Topics include various bug fixes and improvements from the previous tutorials, saving data from scriptable objects, deleting profile data, adding a confirmation prompt, backing up save files, and more!
    The video is separated by timestamps where each timestamp is mostly independent from the others in the video. So feel free to skip passed timestamps that don't interest you.
    Thank you for watching and I hope you found something useful out of this video! 🙂
    ► 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:42 Removing the 'ref' keyword
    1:42 Removing the sceneUnloaded event (MissingReferenceException)
    3:41 Setting the first selected button alternative
    5:15 Persisting data for Inactive (disabled) GameObjects
    6:08 Persisting data for Scriptable Objects
    10:51 Deleting Data for a Save Slot
    16:20 Creating a Confirmation Popup
    23:55 Improving Auto Saving
    26:47 Backing up Data Files
    32:26 Outro
    ► RESOURCES
    Ref keyword and when to use it - www.educative.io/edpresso/wha...
    Ref keyword C# docs - docs.microsoft.com/en-us/dotn...
    SceneUnloaded Event Unity Docs - docs.unity3d.com/ScriptRefere...
    FindObjectsOfType Unity Docs - docs.unity3d.com/ScriptRefere...
    Excellent tutorial by Samyam on Scriptable Objects - • The Ultimate Introduct...
    Thread that discusses complications with serializing Scriptable Objects - forum.unity.com/threads/seria...
    Scriptable Objects Unity Docs - docs.unity3d.com/Manual/class...
    ► GITHUB PROJECT
    The '4-save-slots-implemented' branch is the starting point of the project for this tutorial and the '5-bug-fixes-and-polish' 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
  • Навчання та стиль

КОМЕНТАРІ • 108

  • @ShapedByRainStudios
    @ShapedByRainStudios  2 роки тому +9

    Feel free to come by my Discord server and ask questions, suggest a video topic, or just hang out! ➔ 📱discord.gg/99gcnaHFf9
    Another FAQ that didn't make it into this video involves how to load a specific scene on startup rather than the hard coded "SampleScene" used in these tutorials. In short, one way to go about this is saving the current scene the player is in as part of your GameData and then loading the value from that when we transition to the initial scene from the main menu. A detailed step-by-step solution can be found under the FAQ section on my Discord server under the _loading-the-most-recent-scene_ channel for those who would like more guidance.

    • @dmas7749
      @dmas7749 Рік тому

      any reason you can't fit it here or on the github?

  • @mattsponholz8350
    @mattsponholz8350 2 роки тому +33

    Mad props for your extended work and retrospective here! I can't tell you how many times I've gotten to a final video in a series only to get obscure errors and see a ton of comments trying to debug the issues. seriously, thank you for this man :)

    • @ShapedByRainStudios
      @ShapedByRainStudios  2 роки тому +4

      You're welcome and thank you so much for the kind words! I'm really glad to hear that! 🙂

  • @reynielmahinay7028
    @reynielmahinay7028 Рік тому +6

    The best series about Save & Load System in history of youtube!

  • @jeshuanavarrogarcia
    @jeshuanavarrogarcia Рік тому +1

    Thanks for the series and this video! Hopefully all the tutorials out there do something like this. Thanks!

  • @epiphanyatnight8732
    @epiphanyatnight8732 Рік тому +2

    This series helped me greatly. The clarity is perfect, thank you very much!

  • @heattik
    @heattik 2 роки тому +3

    Thank you very much for fixing the bug, I like it.

  • @edganmolla7422
    @edganmolla7422 Рік тому +1

    what an amazing series. i cant thank you enough for providing such valuable information!

  • @KademirGames
    @KademirGames 11 місяців тому +1

    thanks, helped a lot, very underrated channel, deserves more

  • @yasin_ozbek
    @yasin_ozbek Рік тому +2

    This tutorial helped me a lot, thank you

  • @TwoHornsYoutube
    @TwoHornsYoutube 4 місяці тому +1

    Thank you for such an awesome video series... This helped me out so much!

  • @nakato-bz4fr
    @nakato-bz4fr Рік тому +1

    awsom work! I like your coding style and your explanation make me very clear.

  • @remiboutroux8744
    @remiboutroux8744 2 місяці тому +1

    This tutorial is absolutely amazing, thanks a lot

  • @AMKHStudio
    @AMKHStudio 7 місяців тому +2

    Thank you very much and a big hug from Brazil!!

  • @mirtzata
    @mirtzata Рік тому +11

    I was afraid to start working on a save system due to all the cases that need to be covered. But damn, this tutorial is pure goal, you've covered everything a newby can imagine they need and don't understand how to do. Keep these tutorials coming!!!

  • @cyq3255
    @cyq3255 Рік тому +1

    Amazing series thank you.

  • @vincentsplatterent66
    @vincentsplatterent66 Рік тому +3

    One of my biggest pain in making games in Unity, as noob, has always been the save/load system because there is so much to go through.. but this series covered every step so perfectly and so well explained! I'd like if one day you can cover a proper way to impement an inventory system like adding or removing an item and keep it update with the save/load system.

  • @fakenuzz
    @fakenuzz Рік тому +2

    Just got through all of your Save & Load System videos and truly appreciate the knowledge sharing and clean-cut videos. Not only did you help me build it out step by step but provided clear understanding on why you were taking that approach, which in turn made me learn a lot. I was able to easily integrate this into my game with a few tweaks. Much appreciated Trever, I look forward to checking out some of your other videos!

    • @ShapedByRainStudios
      @ShapedByRainStudios  Рік тому

      Thanks so much for the kind words! I'm really glad to hear the videos helped!

  • @Blu3zStudios
    @Blu3zStudios 10 місяців тому

    just finished everything in the series. Took me 2 weeks to learn and write down everything (I handwrite it ) so I can better understand and write myself. Thanks a lot, this is amazing !

  • @nicholassantorelli9166
    @nicholassantorelli9166 Рік тому +3

    Wow, love these tutorials! I wish I had them 3 years ago when I was trying to solve these specific problems...
    A quick note about autosave lagging the game, it's fairly easy to throw such file IO operations onto a second thread using a System.Tasks. Just be sure to serialize the game state on the main thread.

  • @jkRatbird
    @jkRatbird Рік тому +1

    here for the tutorial and just 30 seconds in but that game looks TIGHT! Reminds me a lot of knytt, the game that got me into indie dev!

  • @dominikfischer5175
    @dominikfischer5175 Рік тому +3

    This tutorial series is probably one of the best, if not the best I´ve ever seen for unity. You sir, are a legend.

    • @ShapedByRainStudios
      @ShapedByRainStudios  Рік тому +1

      Thanks so much for the kind words! That means a lot and I'm glad you found the series helpful! 🙂

  • @degs0338
    @degs0338 Рік тому +5

    Im late to the party and I never take the time to comment a video, but I have to say that your tutorials were amazing, they helped me a lot not only to build the save system, but also to understand a lot about programing.... thank you so much.

    • @ShapedByRainStudios
      @ShapedByRainStudios  Рік тому

      Thank you so much for the kind words! That means a lot and I'm really glad the videos helped! 🙂

  • @burgundyboysyt2272
    @burgundyboysyt2272 Рік тому +1

    Your probably the best person to watch tutorials You explain them so well Thank you for these tutorials it really help

    • @ShapedByRainStudios
      @ShapedByRainStudios  Рік тому +1

      Thanks so much for the kind words! Really glad to hear you found the videos helpful!

  • @mikeohc
    @mikeohc Рік тому

    This is an amazing tutorial. I think the main benefit of SO is storing a large amount of data. For example, we know the coins are a list of object with UID, so decoupling UID, along with save/load from the coin.cs can keep things modular. Have an SO to keep a list with UID and position of each coin so data manager can reference the SO asset and instantiate the coins rather than disabling it. This is more scalable, and less prone to messing with prefabs.

  • @ultimatesin3544
    @ultimatesin3544 Рік тому +2

    23:55 If you want to save your game with zero lag you can use the C# keywords "async" "await" to create a Task that runs on a secondary thread, you can use this for read/write data and pretty much do anything other than reference the UI (which runs on primary thread). There are tutorials on UA-cam, it's not as fully fleshed out as other languages and the syntax is kinda weird but it gets the job done and is pretty useful for executing heavy functions without impacting performance

  • @vicious3526
    @vicious3526 9 місяців тому +2

    Thank you so much. I've looked through a bunch of save tutorials on youtube, including some big programming channels and I can confidently say that this was the best series by far. Thank you so much for all your effort.

    • @ShapedByRainStudios
      @ShapedByRainStudios  9 місяців тому +1

      Thanks so much for the kind words! That means a lot and I'm really glad to hear the series was helpful! 🙂

    • @vicious3526
      @vicious3526 9 місяців тому +1

      Hey random question I'm struggling with. I'm trying to expand on your coding by adding a few things. I'm trying to add a system where I can load in other things. I've been able to have this system save/load other additional systems and assets, but the problem is when I load specific scenes when loading. I end up causing infinite loops and don't fully understand why, I do know it causes the OnEnable to loop infinitely . Here's my class I'm trying to use to load a specific non-starting scene on continue or load:
      public class SceneManagement : MonoBehaviour, IDataPersistence
      {
      public Scene scene;
      public string sceneName;
      //public string scene;
      void update()
      {

      }
      public void LoadData(GameData data)
      {
      sceneName = data.Area;
      scene = SceneManager.GetActiveScene();
      if (sceneName != scene.name)
      Debug.Log("Test7");
      SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
      }
      public void SaveData(ref GameData data)
      {
      scene = SceneManager.GetActiveScene();
      sceneName = scene.name;
      data.Area = sceneName;
      Any help would be appreciated
      @@ShapedByRainStudios

  • @user-zc9bh6ur4z
    @user-zc9bh6ur4z 9 місяців тому +1

    I don't usually comment, but I need to.
    You are a very kind and excellent person. I hope this series helps more people.
    I'm very grateful to you.

    • @ShapedByRainStudios
      @ShapedByRainStudios  9 місяців тому

      I really appreciate the comment and I'm glad to hear the series was helpful! 🙂

  • @dmas7749
    @dmas7749 Рік тому

    i like the "slot zero" autosaving convention, where you have slots 1-4 like in these videos, but a hidden 0th slot that only shows up when using loading, this way it doesn't overwrite anything and you don't have to worry about getting corrupted data thanks to what is supposed to be a convenience

  • @bustycake9145
    @bustycake9145 Рік тому

    Thank you so much for this wonderful tutorials, i wonder if you can make a tutorial on to set up shop mechanism in the game using this json utility

  • @piobug
    @piobug Рік тому +1

    Thanks!

    • @ShapedByRainStudios
      @ShapedByRainStudios  Рік тому +1

      You're welcome and thank you so much for the donations! That means a lot! 🙂

  • @francfores7986
    @francfores7986 Рік тому +1

    Hi! First of all, I wanted to say that this series of tutorials were awesome. They really helped me to set up my menu and put up the save system up. I'm dealing with a problem now, the thing is that I don't have the same menu system that you use in the tutorials. I have a Play button, when I click it the slots pop up, and when I click one of them, the options to start a new game, continue and delete pop up. The "New Game" option works when the slot is empty, and it works properly in-game. When I exit also saves the data in the correct slot. If I load the menu again, I have a "Continue" button that works well and a "Delete" button that I haven't implemented yet, but if I try to overwrite the save with a new game, it loads the current slot instead of creating a new one.
    This is my New game function:
    public void NewGame()
    {
    this.slotData = new SlotData();
    }
    That is called from the MainMenu script when rthe button is clicked:
    public void OnNewGameClicked()
    {
    DisableButtons();
    DataPersistanceManager.instance.NewGame();
    SceneManager.LoadSceneAsync(newGameScene);
    }
    Can't really figure out why it is not working, as it should do the same as loading the game but with an empty slot. I would really appreciate if you could give my any advice :)

    • @ShapedByRainStudios
      @ShapedByRainStudios  Рік тому +1

      Hey there! Really glad to hear that the tutorial series helped! At first glance, it looks like it might be that you need to save the game before you load the new scene. Assuming you took out the sceneUnloaded event (which is recommended), it's no longer saving your data automatically on the scene transition. NewGame() only initializes the gameData variable, but you'll want to write that data to a file before you load the new scene so that when the game loads during sceneLoaded, it'll be your new game data instead of the previous save.
      TL;DR - I imagine the below should fix your issue. See 1:42 in this video for a bit more context.
      public void OnNewGameClicked()
      {
      DisableButtons();
      DataPersistenceManager.instance.NewGame();
      // add this line so your new game writes to the file before the next scene loads
      DataPersistenceManager.instance.SaveGame();
      SceneManager.LoadSceneAsync(newGameScene);
      }
      Best of luck and I hope that helps! 🙂

    • @francfores7986
      @francfores7986 Рік тому

      @@ShapedByRainStudios You are completely right. I am working with another programmer and the recently merged version eliminated the scene unloaded and the ref keyword as you suggested, so it makes sense that the new game data needs to be saved manually as now it is not saved with the scene event. Thanks a lot! I was looking for a fix for my anterior save system and found this tutorial series, since then I subbed and I don't miss a video. I really enjoy the way you explain things and the quality of your videos is tremendous. Keep up the good work, it really helps devs with little experience like me :)

  • @gxguy2906
    @gxguy2906 Рік тому

    Please add additive to this series if possible. Thank you so much for your hard work!

  • @thecreator9625
    @thecreator9625 День тому +1

    How come some of my data gets saved in between scenes perfectly, but some get reset on entering a new scene?

  • @005Racot500
    @005Racot500 Рік тому +1

    Hi. Thanks for the nice save/load system videos.
    It would be nice to implement save and load logic for dynamically spawned objects by game session. For example - save load instantiated loot on the floor after destroying the chest.

    • @ShapedByRainStudios
      @ShapedByRainStudios  Рік тому

      Hey and thank you for the kind words, I'm glad to hear you found the videos useful! What you mentioned would have been a good thing to include in this video looking back on it, as I've gotten several questions about that since.
      For this type of Save & Load System, you would Save and Load the game data using the script that's spawning those objects rather than the objects themselves. This should work in most cases and is what I would recommend.
      For the special cases where it won't work that way, you can add a method to the DataPersistenceManager to add an object to the IDatapersistence Objects list and then call that from your instantiated objects Start or Awake method - so that when the object instantiates, it adds itself to the list to be saved/loaded. That said, I would recommend the previous approach I mentioned since this creates somewhat of a circular dependency between that object and the DataPersistenceManager.
      Hopefully that helps a bit and best of luck! 🙂

  • @MarekNijaki
    @MarekNijaki 2 роки тому +2

    Beautiful tutorial series. You managed to explain everything needed for good base architecture of game save system. Good job!
    Btw: did you considered creating save system using Iserializable and INotifyPropertyChange interfaces? I tried to understand how to use those two but failed miserably 😩

    • @ShapedByRainStudios
      @ShapedByRainStudios  2 роки тому +1

      Thank you for the kind words and I'm really glad you found the series useful! 🙂
      I'm personally not very familiar with either of those interfaces. My understanding though from a quick Google search is that ISerializable is used for providing a custom binary serialization. From what I can tell it seems to be how you'd go about serializing objects for the Binary Formatter - which I don't recommend using all together for the reasons mentioned in the first video. That's just a quick Google search on my end though - so perhaps it has other uses I didn't see that don't involve the Binary Formatter.
      For INotifyPropertyChange, at least from the Microsoft docs, seems like it's focused on form data in C# server/client applications. I see the potential of binding to variable state to easily update the game data; however, I'm not sure how appropriate that interface would be in the context of a game vs a C# Web App - which looks like it would use that interface to keep data in sync between multiple clients and a server.
      Again - not too familiar with those interfaces myself so take the above with a grain of salt; however those are my initial thoughts from a quick Google search. I hope help a bit!

    • @MarekNijaki
      @MarekNijaki 2 роки тому

      @@ShapedByRainStudios thx for answer

  • @ven6815
    @ven6815 Рік тому +1

    Thank you for your amazing tutorials, I learned a lot more about programming from following them.
    I have a question tho: when creating the backupFilePath string I tried to use Path.Combine() instead of adding them together, and it didn't work, what causes that?

  • @connorpayne2671
    @connorpayne2671 Рік тому

    One thing that would have been very useful is saving multiple game objects that are around the scene. I'm making a game that has a bunch of cubes that need to be saved. This did actually help me a lot for the points though. I'll be adding the high score, coins, and other things to the script

  • @shubhrojyotikabiraj8322
    @shubhrojyotikabiraj8322 Рік тому

    Hello Trever love this video 🥰, I wanted to know what i have to change or add in this system if i have to Restart the game from Game Scene

  • @IheartGames646
    @IheartGames646 Рік тому

    i have followed all 4 tutorials and i have no errors, as you mentioned that this save system can be applied to any game in the first tutorial i have and it does work however my player position gets updated in the files but when i load the game the player is not in the same position as i left him. this is for a 3D Game im not sure if thats the problem

  • @Kaonuri
    @Kaonuri 2 роки тому

    You can inherit ScriptableObject with [System.Serializable] like SerializableScriptableObject. This way can save scriptable object directly to json.

    • @ShapedByRainStudios
      @ShapedByRainStudios  2 роки тому

      Hey there! 🙂Thank you for the comment, but to my knowledge the Scriptable Object likely isn't persisting like you think it is in this scenario.
      If you look at your game data file, is it saving as an instanceID? Maybe I should have elaborated a bit more in the video, but if you try to save them directly like this (at least using the JSON Utility) it'll save an InstanceID instead of the actual data. Per Unity docs, InstanceIDs change between Player Runtime and Editor Sessions, so it's not a reliable way to refer to an object. - docs.unity3d.com/ScriptReference/Object.GetInstanceID.html
      Of course, if what I described is not what you're seeing and you've managed to save the data consistently by Serializing a Scriptable Object directly, I'd be really interested to hear a bit more! Any resources I found and my own experimentation suggest against this, but many resources I looked at were a bit dated and I definitely could be wrong!

  • @_LI1AM
    @_LI1AM 5 місяців тому

    How do you save in which scene you’re in and make it load that scene

  • @minkhantnyinyi1049
    @minkhantnyinyi1049 9 місяців тому

    How can i use this system for multiples different scenes?

  • @AMKHStudio
    @AMKHStudio 6 місяців тому +1

    Unfortunately I'm having a persistent and inconvenient problem. Whenever my character "dies" or "changes scene/phase", Game Data stops saving! : (

  • @lordeoflights8638
    @lordeoflights8638 4 місяці тому

    I am using yarn spinner for dialogue, how can I save dialogue progress?

  • @xiakun592
    @xiakun592 5 місяців тому

    I am a beginner programmer and I really like your lessons. You explain and show it perfectly.
    I have a problem. I don't know how to save completed dialogs in different save slots in the main menu.
    The scripts are completely written with two lessons on dialogs and the main menu.
    Please help me.

  • @bfowler1321
    @bfowler1321 10 місяців тому

    Amazing tutorials. I know you somewhat mentioned it in your discord but i was curious about setting up more of a heirarchial type of save format with files/folders. I guess i mean more modular? Have the ability to encrypt certain files that users shouldnt be able to change and allow some to be in plain text(i.e. inventory adjustment, player in game money)
    Just curious. Thanks again for all of your knoweldge

  • @dm1tryrin
    @dm1tryrin 4 місяці тому +1

    Hello! Thank you very much for the video! I ran into a problem - I made a save system based on your videos. In my game, the checkpoint system is similar to Hollow Knight - there are places (relatively: a bench) where the player can save the game. By default, all checkpoints are inactive - the first time you save, the value of id and boolean becomes true. But the problem is this - when I activate a checkpoint on scene 1 and save, then I go to scene 2, then I return to scene 1 and the checkpoint is not active again. Hint where to look. How to initialize data from a file when moving to a new scene?

  • @caravanhati9202
    @caravanhati9202 6 місяців тому

    i have used your save and load system but i dont know how to save inventory. can you help

  • @onuroguz940
    @onuroguz940 Рік тому

    Thankyou for the videos. But cant get a save file. when I quit the game. I got error :"No data was found. A new game needs to be started before data can be saved". :(

  • @NightRunStudio
    @NightRunStudio Рік тому

    I know I'm a little late to the party... but I have an issue when clearing data from a file. After the file is cleared, it still seems to be held in the game's memory.
    If I start a new game, it loads that last saved data (even thought the save slots are wiped, and all of my save slot folders are empty on my machine). If I exit the game completely, and then start a new game, it works, but for some reason, I can't start a new game during the same session that I deleted the save slot.
    Anyone have any ideas? I've looked over the Github files a gazillion times and can't get to the bottom of this.

  • @moose6459
    @moose6459 2 роки тому +2

    Alternatively to your storing scriptable objects approach, I created a GUID ID and save that to json. When I load it, I compare it as the key for a dictionary in my GameManager to retrieve the scriptableobject I want to reference
    Since a scriptable object is already essentially saved data, there’s no need to re-save it in each build when you can just reference it

    • @ShapedByRainStudios
      @ShapedByRainStudios  2 роки тому +1

      Oh interesting! I'll have to play around with this approach a bit.
      However, I would be a bit cautious with this approach since the Unity docs are pretty explicit about how Scriptable Objects are *not* to be used for saving data. - docs.unity3d.com/Manual/class-ScriptableObject.html
      You _might_ run into unpredictable behaviors down the line where, in a production build, the data in your Scriptable Object Assets will reset to default values upon clearing cache or other temporary data.
      All of that said, it _could_ also be fine! I personally am not knowledgeable enough on exactly how Scriptable Objects are stored in a production build. I'll certainly play around with this idea a bit myself, but just wanted to add a word of caution for you and others who read this comment looking for a more convenient solution.
      Thank you for sharing it! 🙂

    • @moose6459
      @moose6459 Рік тому

      ​@@ShapedByRainStudios Ah, I had thought the discussion in the video had been regarding using predefined data in scriptable objects, my bad.
      I stopped using SO's for changing data after learning my mistake once or twice. The biggest issue with changing data in a SO is it will affect every object referencing the SO in the scene. I tend to use SO a lot (enemy behavior, effect system, spell system, inventory system) which I all want to be unique instances but can reference the same data.

    • @ShapedByRainStudios
      @ShapedByRainStudios  Рік тому

      @@moose6459 Ah gotcha - yeah I think I would reword parts of that section if I did this video again, haha. I think the points could have been more clear overall.
      I absolutely agree with your perspective on SO's and that's a great example of why you wouldn't want to store state data in them. Thank you for the thoughtful response! 🙂

  • @jimmyyu3383
    @jimmyyu3383 Рік тому +1

    what an amazing series of videos!!! One thump-up (well, total should be four) is definitely not sufficient.
    Easy to understand (even for a newbie like me).
    The way unityaction is used totally beyond my imagination. I would have used unityevent to send across scripts to achieve the same effect.
    One little issue (for my own development) is how to "save" if the gameobject is not active. For example, if the coins are not active, we cannot save it (though the loading part is solved).
    Trever resolves this issue by disable the visual effect of the coin and not setting the coin as inactive (if I am not mistaken). This is one way. In this case, I think the collider also needs to be set inactive.
    For the scriptable object, when I watched the first video, I already though it would be better to use monobehavior and use proxy to save. Glad I am in line here.
    btw, I have a newbie question.
    I saw there are a lot of "this" in the scripts. E.g. this.gameobject, this.gamedata...
    my question is whether this "this" is necessary. Or what is the purpos of "this". For example under NewGame(), cant I just use "gameData = new GameData();"?
    rather than
    "this.gameData = new GameData();"??
    As to next video, it would be good to learn about the save and load in additive scene. It seems additive scene is quite common in game development also.
    Thank you very much. Look forward to your videos.

    • @ShapedByRainStudios
      @ShapedByRainStudios  Рік тому +2

      Hey there! Thank you for the kind words and appreciate the thoughtful comment! 🙂
      As for your question about the "this" keyword - it is _not_ necessary in most cases that I use it for these tutorials and can be omitted.
      The "this" keyword is used to refer to a variable that belongs to that class. For the below example, it is not necessary.
      // below two lines will do exactly the same thing
      this.gameData = new GameData();
      gameData = new GameData();
      However, the "this" keyword does have some practical cases as well. If you have two same-named variables with different scopes - one at the class level and one as a method parameter - it can be used to differentiate between them. For example,
      public class Test
      {
      private GameData gameData;
      private void SetData(GameData gameData)
      {
      // left side is the class-level variable, right side is the parameter
      // without it, you'd be referencing the parameter on both sides
      this.gameData = gameData;
      }
      }
      Alternatively to the above, if you didn't want to use "this", you just would avoid having the same variable name.
      private void SetData(GameData newGameData)
      {
      gameData = newGameData;
      }
      I have a habit of using the "this" keyword myself as a personal coding preference to make clear when I'm modifying class variables. I'm not the most consistent with using it though - so you'll see it some places and not other places which I can imagine might come across as confusing.
      There are some other uses as well, but what I described above seems to be one of the most common. Here are the official docs as well if you want to read up a bit further - docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/this
      TL;DR - Using the "this" keyword is fairly subjective in most cases. Some like using it and others don't. Most (if not all) cases of using "this" in these tutorials can be removed without changing the codes functionality.
      I hope that helps clear it up a bit and great question!

    • @jimmyyu3383
      @jimmyyu3383 Рік тому

      @@ShapedByRainStudios Thank you very much. It is helpful.
      Btw, I think I found one issue (not sure if this is personal to my case). I set up a cover page for player to enter some info e.g. name between New Game and SaveSlots. So, when I click new game, it will go to a page to enter information first and then click next to the saved slot to choose a slot.
      When the game was created, everything works fine.
      If I exist back to the cover page, and click continue, it will load back the saveed game, which is fine.
      The issue arises though for the info entered by the player. Because the current code under "continue" will have the game "saved again" before it is loaded to the saved game. Since the player does not enter any name when clicking continue, the saved game after loading will have an empty name (and other information which is to be entered will be null or zero).
      i.e. the "continue button" will save an empty name first and then load the saved game.
      So, whatever keyed in in main menu will be overrided with null / 0 when clicking continue.
      The solution I can think of is to load the saved first and re-saved again when clicking continue. But then if i click new game, the data will be preloaded, which causes other issues.
      Another way is to separately save the entered data and do a check before loading.
      Anyway, I am trying to "fix' this issue (could be specific to my case).
      Thank you again.

    • @jimmyyu3383
      @jimmyyu3383 Рік тому

      LOL I found out a quick fix. I comment out the "DataPersistenceManager.Instance.SaveGame();" in continue and load game. So it would not save once more before loading saved game.
      Not sure if this will cause other issues. In any case, will share it here if I encounter any issues.

    • @ShapedByRainStudios
      @ShapedByRainStudios  Рік тому +1

      @@jimmyyu3383 Hey! I'm glad you figured something out for it. If I understand the issue correctly, it sounds like it might just be due to the ordering of things happening. Here's how the system in the videos works regarding using the Continue button from the main menu that might provide some clarity.
      1 - Main Menu starts up. The DataPersistenceManager loads data on startup to be the most recent saved game into the gameData variable. So right at start up, the gameData is up to date with the most recent saved game.
      2 - Continue button is clicked and the scene transition happens. Before we transition scenes, we save the game - which in this case is just saving the same data that existed before (unless modifications were made to the data via the main menu - keybinds, graphics settings, volume settings, etc..).
      3 - The new scene loads and the DataPersistenceManager still points to the most recent saved data - so that's the data the gameplay scene is loaded with.
      Of course, if you don't have any saved data to begin with - step #1 will result in not loading any data - and therefore you'd want to disable the Continue button because there is no data to continue from.
      I'm not sure what your code looks like for the input by the player, but it does sound like maybe something there might make this differ from the tutorials in a way you'd want to not save the game when pressing the Continue button. The only thing you'd be missing out on there is if you want to save settings (keybinds, graphics, volume, etc..) from your main menu - but that can also be handled in other ways.
      So if it's working the way you have it modified - I would stick with that unless you start seeing other issues. Hopefully the above helps a bit though! 🙂

    • @jimmyyu3383
      @jimmyyu3383 Рік тому

      @@ShapedByRainStudios Thank you for your reply. The quick fix does not fix my issue if the game is closed. I.e. exit play mode and enter play mode again. It is because when entering play mode, the scene is loaded with an empty name again.
      What I did is adding a page allowing player to enter name, and the data persistence manager will use save function to save the name into game data. And then load it again when the gameplay scene starts. It works in new game but when loading, (Whether via continue or loading specific saving slots), the name disappears. I basically move the "new game" function to another UI page only.
      In any case, I re-wrote using most of your codes but changed the logic of saving and loading.
      1. Auto save to default slots i.e. 0 (but triggered only when certain events happen e.g. level up, closing inventory page)
      2. in gameplay, player can choose which slots to save and load (i.e. adding a menu in gameplay mode)
      3. Using unityevent and not interface. This is because I am not familiar with interface system. Also, unity event gives me flexibility as to when and which script to save. E.g. when player updates equipment slots, only equipment slots data are updated and then saved.
      4. Hence, I created a shared inventory for all characters with unity event system. I am not sure how to achieve shared inventory with interface....
      After rewriting, I am able to save the name even if I exit play mode.
      Again, appreciated your tutorial. Without it, I cannot create the save-load system.

  • @FurbyOfDeth
    @FurbyOfDeth Рік тому

    so how much or what can i change in GameData without braking the save file. idk how to know what i can do when i update my game without making all the old save files nolonger work

  • @poly_elina
    @poly_elina Рік тому

    How would I go on about implementing saving settings (like audio volume) into this system, so it doesn't delete the saved settings when deleting the save game?

    • @mikeohc
      @mikeohc Рік тому +1

      playerprefs is usually the way for storing settings like that.

  • @darkman237
    @darkman237 2 місяці тому +1

    But will it work in a game build?

  • @joakimaz
    @joakimaz 2 місяці тому

    Hey man, great tutorial videos, watched them all. Now, can I make a request? Is it possible for you to create a video in which you show us how to modify this save system so instead of choosing the save slot we just create a default save when we press new game, and then while in game the player can save the game by accessing the pause menu. Like, if the player clicks the Save Game button a window would appears and in there he could see all save files (included the default one create at the new game) and the player could overwrite one of those, but also, there would be a text box where the player could enter the name of a file and then save the file with that name. I tried to implement this but with no success. Sorry if there are any errors in my English, not native. Thank you anyway.

  • @ImaginatorPage
    @ImaginatorPage 2 роки тому

    Hey there again Trever! For some reason my dialogue panel is still displayed after the last line of dialogue. For example, if the last line is "goodbye" it displays the line normally, but when pressing Space to continue, the dialogue panel stays on the screen, without any text on it, instead of disappearing. Then only when pressing Space again it disappears. After every last line I'm getting this blank panel and I even tried removing some lines from the DialogueManager script but I couldn't fix it at all. Do you have any ideas on what might be causing this issue? Thanks in advance!

    • @ImaginatorPage
      @ImaginatorPage 2 роки тому

      I forgot to mention, it only occurs if there are no dialogue lines after making a choice. For example I made a light switch as a npc with 2 choices (turn the lights on or off) and there are no lines after the choices. Then, after selecting any of them, the blank panel is displayed.

    • @ShapedByRainStudios
      @ShapedByRainStudios  Рік тому +2

      Hey there! I know of a couple others that also ran into a similar issue. Unfortunately though, I don't remember exactly what they did to fix it. Here's some troubleshooting steps that should help us narrow down what's going on (which you may have already tried).
      1 - Run through your Ink file in the inky editor. Does it have a blank line when playing through? Even if it doesn't, it could be something to do with your Ink file. Try putting a '-> END' divert in after each choice so the story knows to come to an end at that point (if there isn't already one). Some others have had issues with the Unity integration when missing that END divert. Example below:
      * Choice 1
      -> END
      * Choice 2
      -> END
      2 - Put some Debug.Log() statements around the DialogueManager. Specifically in and around the ContinueStory() method. Confirm that this is getting called how you'd expect and only getting called exactly once per button press to continue. If not, it may be an issue where it's getting called twice per frame resulting in a blank panel somehow.
      3 - Since this is happening at the very end of the dialogue, also put some Debug.Log() statements in the ExitDialogueMode() method and try to track exactly what's happening when dialogue exits. Is it getting called before or after the blank panel? That'll help you narrow it down to whether or not it's occurring when dialogue exits.
      I hope that helps a bit! Best of luck!

    • @ImaginatorPage
      @ImaginatorPage Рік тому

      @@ShapedByRainStudios Yeah testing things with debug.log will surely help to find out what's exactly happening so we can fix it! I'll definitely do it, thanks again for the support!

  • @heattik
    @heattik 2 роки тому +1

    And why in
    "Player Script"
    public void LoadData(GameData data){
    if (currentScene == "House_1")
    this.transform.position = data.playerHomePosition;
    else if (currentScene == "SampleScene")
    this.transform.position = data.playerPosition;
    }
    if() not working???
    It saves the player's position but doesn't load it.

    • @ShapedByRainStudios
      @ShapedByRainStudios  2 роки тому +1

      Hey there! I'm not sure how you're populating the currentScene variable, so I imagine that _might_ be where the issue is - since everything else looks fine.
      For troubleshooting, make sure currentScene is what you expect it to be. Adding a Debug.Log(currentScene) statement should result in the string you're expecting as the scene name. You can get the currently running scene with the below code.
      // at the top of your script
      using UnityEngine.SceneManagement;
      // wherever you're initializing the scene name (I would do this directly in LoadData(..))
      string currentScene = Scene.name;
      Docs for that can be found here - docs.unity3d.com/ScriptReference/SceneManagement.Scene-name.html
      I hope that helps!

  • @TheTerspet
    @TheTerspet Рік тому +1

    i followed along on all 3 videos, it took me roughly 10-11 hours to finish , and i am amazed to see how much has to be considered when doing something like a save system, so very much thanks for you for your hard work! i only have one question though , everything is working btw, no errors or smth, i only have the problem that my character starts on a completly different position than what i want to when starting a new game, do you know by any chance how to fix it? its like my character wants to start at 0 ,0 ,0 but there is a wall so it puts me right next to that wall, dunno how else to explain it better

    • @TheTerspet
      @TheTerspet Рік тому

      okay okay, after writing this, i immidiatly tested it myself, and when a new game starts , my player is always starting at position 0 0 0 , so i need to keep that in mind for future levels to set my character at 0 0 0 and start building around that for now, thanks again for that big tutorial

    • @ShapedByRainStudios
      @ShapedByRainStudios  Рік тому

      @0%9F%98%80el/UC4_V6cNGvQVHa5dS5skAQcg Really glad you found the videos helpful and props to you for making it through the series! 😁 If it helps at all, I'll try to give a bit of guidance below for managing the players starting position.
      That initial (0,0,0) starting position is determined by what's declared in your GameData.cs constructor. Changing it there should change the starting position of your player. If you need to manage and persist multiple starting positions (for different scenes/levels), you could expand the data to include multiple starting positions and then create a small system to determine which one is needed at startup.
      If you're not familiar, looking into OOP (Object Oriented Programming) will help a lot with understanding how to best structure your data. For example, if you have a bunch of levels, creating a LevelData object with data specific to each level (like the players position in that level) might be a good way to go (see below for some rough pseudo-code).
      // the LevelData class
      [System.Serializable]
      public class LevelData {
      public Vector3 playerPos;
      // any other data that's specific to the level
      ...
      public LevelData() {
      // the below will make the player start at (2, 3, 0)
      playerPos = new Vector3(2, 3, 0);
      }
      }
      // Your GameData class then can maintain data depending on the level
      [System.Serializable]
      public class GameData {
      // could instead do a LevelData[] or even a Dictionary where the string corresponds to the scene name for that level
      public LevelData level1Data;
      public LevelData level2Data;
      ...
      }
      I hope that helps a bit and best of luck to you!

  • @SilverReaven
    @SilverReaven Рік тому +1

    Hello I know I’m a little late but i am in a little struggle is there a way to save a scene and reload it when pressing the Save Slot where it should be saved Thanks in advanced

    • @ShapedByRainStudios
      @ShapedByRainStudios  Рік тому +1

      Hey there! I actually have a detailed answer archived for this on my Discord server. Check out the FAQ forum post called 'How do I load the most recent scene?' which should help give some guidance on doing so. Best of luck! 🙂

    • @SilverReaven
      @SilverReaven Рік тому

      @@ShapedByRainStudios thanks

  • @Serpent.Xenospire
    @Serpent.Xenospire Рік тому

    How i can load my data by pressing button (Ex: Money)

  • @TheLunarah
    @TheLunarah Рік тому

    I love you

  • @joelfrom08
    @joelfrom08 Рік тому

    **Solved**
    don't know if anyone will respond to this, but I have a problem with the confirmation pop up thingy, it gives me two errors.
    One saying "Assets/Scripts/MainMenu/ConfirmationPopupMenu.cs(9,38): error CS0509: 'ConfirmationPopupMenu': cannot derive from sealed type 'Menu'"
    and the other one telling me that this script doesn't contain a definition for gameobjects. these stay, even when taking the script from github
    *Found the solution on the discord, kinda missed the making of the Menu script.*

  • @842p
    @842p 7 місяців тому

    I'm still getting the MissingReferenceException error everytime I save even though I did what was showed in the video. Here is the full error: MissingReferenceException: The object of type 'PlayerController' 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.

    • @842p
      @842p 7 місяців тому

      Another thing, it only happens in certain scenes

  • @barskilinc9128
    @barskilinc9128 9 місяців тому

    I think this is not necassary. With newtonsoft you can easily serialize scriptable objects.

  • @SaikyoEdits_
    @SaikyoEdits_ Рік тому +1

    My goofy ass removing the ref keyword only in the interface script watching as unity crumbles to pieces

  • @reakzez5697
    @reakzez5697 2 роки тому +1

    why is all of these save files and stuff so complicated :( i have literally worked on that for like 4-5 hours and thats only on the first video

    • @ShapedByRainStudios
      @ShapedByRainStudios  2 роки тому

      It's definitely not an easy thing! Hopefully these videos help a bit though!
      I'm not sure on your background, but having a good foundation in C# and other Object Oriented Programming (OOP) concepts will help A LOT with understanding what's going on in this system. If you're struggling through the first video, it could be worth spending more time on C# and OOP fundamentals.
      Persisting data is a difficult topic regardless, but I'm sure you'll be able to get through it with some time! Best of luck to you! 🙂

    • @reakzez5697
      @reakzez5697 2 роки тому

      @@ShapedByRainStudios im trying to make this work on my first project i have even done in unity and C# so yea its really dificult. after 6 hours of work i cant get it to work because maybe some of my scripts like the player and EventSystem is not like what you did

  • @VEOdev
    @VEOdev Рік тому

    I don't see a reason to use ScriptableObject for any load and save system .. as you video says scriptable object are only for static data suck as player base stats or item properties, data that will not be changed any soon, if you don't want to update your game each time you change item properties, it will be better to save all your item properties into JSON file and update it to something like GoogleDrive and then change the data from there, so you don't have to update and re upload your whole game for 1 data.

  • @TheLunarah
    @TheLunarah Рік тому +1

    Please make a course lol