Resetting Scriptable Objects - Unity Playmode

Поділитися
Вставка
  • Опубліковано 11 лип 2024
  • 🕹️Steam Wishlist: store.steampowered.com/app/25...
    ✅🎮👉 Current Build on Itch: onewheelstudio.itch.io/hex-game
    Scriptable objects are a useful tool in the Unity game engine to hold static data. However, if you need to change data or values in a scriptable object at runtime things get a bit tricky. With lifecycle functions like OnEnable and OnDisable or using the NonSerialized attribute we can solve those problems.
    Support the Channel!
    **********************
    ► Buy me a coffee: www.buymeacoffee.com/onewheel...
    ► Shop the Unity Asset Store (affiliate): assetstore.unity.com/top-asse...
    ► Become A Channel Member: / @onewheelstudio
    ► Or a Patron: / onewheelstudio
    ► My video and streaming kit: kit.co/onewheelstudio/tutoria...
    ► Buy a Game Design Book: kit.co/onewheelstudio/game-de...
    Video Gear List (Amazon Affiliate)
    ***********************************
    ► Sony A6100 Camera: amzn.to/32logXz
    ► Sigma 16mm 1.4 Camera Lens: amzn.to/3KA4Wr4
    ► GoXLR (audio interface): amzn.to/35dmr03
    ► Shure SM7B Mic: amzn.to/3fNbV1E
    ► Blue Mic Arm: amzn.to/3tHgwdQ
    Neewer Light: amzn.to/3rD8eRv
    Light Softbox: amzn.to/3GUaHgQ
    Neewer RGB Light: amzn.to/3rCTQJ9
    Other Links
    ************
    Discord: discord.onewheelstudio.com
    Twitter: / onewheelstudio
    Devlog: onewheelstudio.com/
    Twitch: / onewheelstudio
    Timestamps
    *************
    0:00 SOs are awesome, but...
    0:34 Deep Space Directive
    1:00 Change SOs at Runtime
    2:39 Solution #1 - OnEnable & OnDisable
    4:32 Solution #2 - NonSerialized Attribute (!!!)
    5:36 THE END...
    #GameDevelopment #Unity3D #indiedeveloper

КОМЕНТАРІ • 14

  • @OneWheelStudio
    @OneWheelStudio  5 місяців тому +2

    If only I'd got the camera to focus on me and not the microphone.... 😑Guess I'm a bit rusty?
    🕹Steam Wishlist: store.steampowered.com/app/2510180/Deep_Space_Directive/
    ✅🎮👉 Current Build on Itch: onewheelstudio.itch.io/hex-game

  • @iiropeltonen
    @iiropeltonen 5 місяців тому +9

    SO's behave differently when a game is built. When a SO is unloaded it resets in build. This was a "gotcha" I once ran into.

  • @ikelos8190
    @ikelos8190 5 місяців тому +1

    right when i needed this
    thank you so much!

  • @LighthoofDryden
    @LighthoofDryden 5 місяців тому +2

    Wow, very interesting! I had no idea SOs serialized private fields. And I didn’t know how their life cycle worked either.
    I think I’ll still prefer to not modify SOs at runtime… but it’s good to understand the tools more deeply!

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

    I like your teaching approach, thank you for sharing this useful experience.

  • @myk3l9675
    @myk3l9675 5 місяців тому +1

    Thanks for the info!

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

    Lmao that final solution would so easily be overlooked, thank you for that I appreciate you!

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

    on 2023.2.11 I only observe OnEnable being called on domain reload - not when entering play mode.

  • @SunSailor
    @SunSailor 5 місяців тому +2

    The most obviouse approach to "reset" your SOs data, is not using the asset at all, but instantiating it before. A clone is created and the changed values aren't stored into the asset.

    • @OneWheelStudio
      @OneWheelStudio  5 місяців тому +1

      Most definitely. I thought about that approach. For my use case I would need some sort of factory to hand out references to the SOs - to ensure everyone has the same copy. Which is doable but felt more complex than I needed.

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

    cool ...my method is to create a differente class for all the entities or even a whole class for taking care of this, but with "non-serializable" I am going to try.

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

    Thanks for that. But you said the problem started because you needed to update/set different values to the SO, and once you set the variables to private how did it solve your problem? becuase now you can't change these values from anywhere in your game

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

      In a lot of cases I'm using functions to change the values of local/private variables after doing some calculations. You can also use getters/setters that are public to change the values of private variables. Lots of ways to do it ;)
      But in all cases if you don't use the NonSerialize attribute changes made in play can persist out of playmode.