Change Unity Scenes, Keep Data

Поділитися
Вставка
  • Опубліковано 1 лис 2024

КОМЕНТАРІ • 23

  • @RestfulCoder
    @RestfulCoder  2 роки тому +28

    Note: This is NOT a solution for permanently saving game data. This only holds onto state in memory.

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

      what would a good solution be? singletons or dont destroyonload?

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

    Thank you soooo much. I was trying to figure out how to stop my tutorial after switching from one scene back to the original and this method helped me out.

  • @TwinStick
    @TwinStick 2 роки тому +11

    Hey there - this is actually a very bad way to do things. This will not work in a build. If you want to use scriptable objects to reference persistent data, you will need a way to save and load the values from disk and into the instanced copy of the SO in memory.

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

      This tutorial isn't about persisting data to disk, it's about having some data that can easily live between scenes. You could load values from disk to initialize the data in OnEnable, or some other place.

    • @TwinStick
      @TwinStick 2 роки тому +8

      @@RestfulCoder I'm sorry to say, it still will not retain data. The moment the scene is unloaded, it will unload the SO from memory, then when the scene is loaded again, it will revert to it's default state. A better example for this video would be to have a singleton which is told not to destroy on load that holds an instance of the SO. Then in this SO it can hold an array of LevelInfo structs which store things such as visit state, score, time played etc. Then when a level loads, it could query the singleton.LevelInfo[id] - this would still show a good use case for scriptable objects, and be more relevent. This example you have shown will not work in a build.

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

      Yep. This will only work throughout the editor. Once you go to build the game -- the SO will never be persistently updated & saved. SO in a build will only retain the information it had when the game was built. The reason this works in the editor is because it updates in the editor. That goes away completely once you build the game. I know this because my group ran into this issue towards the end of the semester thinking that we had everything working until we went to build the game... Our whole character creation system never actually retained the updated data after closing the game.

  • @Milezperhour
    @Milezperhour 2 роки тому +11

    As a software engineer who has always been curious about creating pixel games, this is incredible. Please keep up with this series! I'd love to see how you add things like menus and sprite animations.
    btw, just subbed to your channel.

  • @hmtken2213
    @hmtken2213 3 місяці тому

    Nice tutorial video sir, i see there is a script that support the switching scene feature. Do you have any video that teach about how to moving scenes in Unity ? Love the way u setup the entrance and the exir

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

    Thanks a lot for this tutorial but this isn’t the best way to store game data. This should be use to set variables to gameObject and it will check if it is true or equal to an number. Using “Files” in binary is the best way to store your data. But this is the best way to store data for beginners. This method works still but not the best :)

  • @Ogamer320
    @Ogamer320 Місяць тому

    thx you helped me with my challange but i had some troubles because i made a cutscene be a another scene

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

    This was super helpful! Thank you for sharing this.

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

    I heard that scriptable objects aren't meant to have their data changed, and will cause errors when running the built game.

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

      That could be the case, I'm not sure. It's worth looking into more if you're far enough along that you're making regular builds. I no longer use Unity so can't advise.

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

      Great tutorial. Why are you not using Unity any longer? Switch to something else?@@RestfulCoder

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

      @Pixelgraft I got tired of learning a framework that kept changing and getting slower. I've been focusing on C++ and SDL2 which are straightforward programming and unlikely to change.

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

    Great video. I used don't destroyOnLoad in my games project, I will use scriptable object now. Also, what's the name of the autocompltion add-on you are using?

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

    my project trouble camera was change everytime while it start
    i use u script and method

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

      I no longer use Unity so can't advise.

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

    Hi ? i hope you can reply to me i want to know how can i follow the camera to my player after changing scene

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

      Look into "dontdestroyonload" and you will find the answer to your questions. It saves a gameobject between scenes.

  • @Motivational-Mango
    @Motivational-Mango 2 місяці тому

    Not good my friend