How to save data between Scenes in Unity

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

КОМЕНТАРІ • 36

  • @Player_Console
    @Player_Console 25 днів тому

    Sir. Thank you very much, I have been searching a lot of time in UA-cam but I got them in your video..❤❤❤

  • @benjaminwillcox7096
    @benjaminwillcox7096 2 роки тому +7

    Good to see a channel with new content! I used this in my game and it works great for keep track of my player's coins between scenes, even once you exit the game if you wish.

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

    Finally someone made video on this thnx.
    hi,
    Kindly make more videos of unity challenges n other projects/tutorials for beginners
    Thanks

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

    Awesome tip! One deficiency though is that if you want to load a scene that doesn't require it and then switch back to another scene that DOES require it, unity might have garbage collected it. At this point is it best to just commit the value to a file, or is there a workaround other than requiring the object in every scene?

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

      Thanks for the feedback! Yes in general we would need a High Level save object attached to every scene that has in turn references to all the other data and probably we could access this HL object in our code instead and ask it for the data that we need.
      Sorry about not explaining that. It is not easy to explain everything in shorter tutorials.

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

    Thank you for this video! Works amazingly!

  • @idanlevovsky8585
    @idanlevovsky8585 8 місяців тому +1

    Great video helped me a lot but something is not working for me when I try to save a 2D list do you know of any problem?

    • @SunnyValleyStudio
      @SunnyValleyStudio  8 місяців тому

      Strange. Maybe because List is reference type so it is connected with SO but not stored in it? I will do my best to test it

  • @eladonstar2721
    @eladonstar2721 2 роки тому +5

    It's good to see scriptable objects era..

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

      Thanks for watching!
      I believe that SO can improve the code behind our games. The only downside is that the code becomes a Unity specific solution.

  • @Subnow127
    @Subnow127 11 місяців тому

    im having this error : The type or namespace name 'FloatSO' could not be found (are you missing a using directive or an assembly reference?)

    • @Subnow127
      @Subnow127 11 місяців тому

      in my script where im accessing my SO

    • @SunnyValleyStudio
      @SunnyValleyStudio  11 місяців тому

      Can you confirm if your script "FloatSO" has the file named the same way? It usually ends up being issue with the names

    • @Subnow127
      @Subnow127 11 місяців тому

      @@SunnyValleyStudio yes I will

  • @risingforce9648
    @risingforce9648 8 місяців тому

    how to persiste TExt componentes? in btween scenes? I need to pass the Text as welll (not only the data)...I need a starting point to every level , in every level I need some kind of thing to start eeverylevel to find text and avoiding Null reference in real time.

    • @SunnyValleyStudio
      @SunnyValleyStudio  8 місяців тому

      Unless you have a lot of data the best approach is to use Player Prefs to persist data between levels. So are good if you remember to keep a references to the ones containing required data in every scene. For persisting data between sessions I like to use JSON serialization and just save that to a file but you can do any form of serialization docs.unity3d.com/2020.1/Documentation/Manual/JSONSerialization.html

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

    Someone help me , just logic stuff. I plan make simple 2d like mario with scoring and has multiple levels. My problem is the leaderboard and its level selection. I would want to place the highest score of players on the board.
    but the problem is how? Like i have multiple levels, so i do this?:
    1.If i have like a level selection for ex level 1, it will get the highest score data i make and send it to level 2 then keep getting high score to reach for ex level 10 but the issue is level selection, what if i just restart different levels via level selection like i restarted level 2 and level 5 so the data changed right ? How do i keep tallying that like to the current level i had completed is like level 20.
    2. For low levels (level 1-40)keep the scoring thing to a minimal like just increase 10 points. But at later higher levels make the scoring thing higher is this the right thing?
    Someone help me. Thanks.

  • @user-zj1yx3vb6q
    @user-zj1yx3vb6q Рік тому

    does this works even if you reload the scene

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

      As long as the scene has a reference to an SO it should not be unloaded. The moment the scene has no connection to the SO it is unloaded from the memory.

  • @pixelpat5276
    @pixelpat5276 2 роки тому +6

    I can't make a game without using So, they are a game changer when you unlock their power

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

      Hey! Thanks for watching!
      The solution with creating a general context scene "Game" and loading additively other scenes is a more generic way to deal with issues like shared code etc. SO are a cool way to deal with those issues but at the same time its Unity specific solution. I try to always keep it in mind that using SO means trading generic knowledge for Unity specific one.

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

      @@SunnyValleyStudio That's a good point about it being Unity specific, definitely don't learn them until you can do it another way first.

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

      @@SunnyValleyStudio Btw do you have any videos about that topic of additive scenes or can you guide me into any resource on that topic, I cannot find much about it - many people mention this, but no one explains how to do that with some examples :(

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

      @@DrakonFirestone Yeah am planning a video about it. Right now a great way to learn about additive scenes is by checking the Unity Open Project unity.com/open-projects

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

      The Wharf person I have to get the chance that bot for a bit better but not sure how long have to get the chance that bot for a bit better

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

    hey I used SO to save my float values. I build the game to my phone and tested it. When I restarted the scen(with a button) the values did not go deleted but when I closed the app and opened it again the values were gone(reseted). But in Unity editor this did not happy when I played the game and closed it the values did not go. please help thanks

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

      Hey! This method is only useful for persisting the value between scenes that actually reference this SO. When you close the app the value is gode by design. Use SO only to decouple your UI from other things. Use Json or some online database to to actually save the state of your game.
      If by any chance the SO doesn't persist the value between scenes just use PlayerPrefs to store it although it should not happen.

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

      @@SunnyValleyStudio oh ok

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

    this is good information but u gotta breath between your sentences when u talk m8. This is truly hard to follow. It's like an atomicbomb with information thrown at u all at once.

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

      Thanks for the feedback! I definitely need to work a bit more on my delivery.