Better Data with Scriptable Objects in Unity! (Tutorial)

Ойындар

In this video, we are going to show you how to use Scriptable Objects to manage your data in Unity.
Download the Unity Royale Project here!
on.unity.com/33FplpG
Learn more about Scriptable Objects here!
on.unity.com/33PzcJR
Get Inspiration on what else to do with Scriptable Objects here!
on.unity.com/2RKXXkK
Chapters:
00:00 Intro
00:30 Scriptable Objects vs MonoBehaviours
01:43 Scriptable Objects as a data container
03:10 Scriptable Objects as “Enum States”
03:44 Runtime Data Editing
Unity Version used 2020.1.2

Пікірлер: 125

  • @fresch4395
    @fresch43953 жыл бұрын

    Like with all tutorials I will think "oh this is sooo easy, awesome" and as soon as I try to use it I will be stumped and look through the docs for like 5 hours a day

  • @Copybook

    @Copybook

    Жыл бұрын

    Docs are important 😌 even though I understand nothing sometimes all day long

  • @misterrhombus

    @misterrhombus

    Жыл бұрын

    That isn't such a bad thing. That means you really want to learn

  • @junyan2604

    @junyan2604

    Жыл бұрын

    sometimes the having the interest to really achieve something is way more important than having the talent.

  • @frostcop6693
    @frostcop66933 жыл бұрын

    Finally a video on this topic

  • @johnx140
    @johnx1403 жыл бұрын

    These are amazing!!! Pls do one for the different audio thingies, and how are they useful.

  • @Daeniak57
    @Daeniak5710 ай бұрын

    EXACTLY what I was searching for the input system and events

  • @syriph2527
    @syriph25273 жыл бұрын

    This looks so useful. Wish I had known about this 2 years ago

  • @kristianthaler6525
    @kristianthaler65252 жыл бұрын

    Thanks, I learned a lot from this.

  • @SpaceDave-on8uv
    @SpaceDave-on8uv3 жыл бұрын

    FixedUpdate sitting in the corner crying

  • @salesman4396

    @salesman4396

    3 жыл бұрын

    It was crying on shoulder of LateUpdate

  • @greglyons288

    @greglyons288

    3 жыл бұрын

    next to the remains of OnAnimatorMove()

  • @kippenegg

    @kippenegg

    3 жыл бұрын

    @@greglyons288 must be just a skeleton at this point

  • @OscarFernandez
    @OscarFernandez3 жыл бұрын

    Nice tutorial. Is there a tutorial like this for the Input System ?

  • @ulti-mantis
    @ulti-mantis3 жыл бұрын

    I'm making a cardgame, and I'm using these A LOT

  • @glannho5459

    @glannho5459

    3 жыл бұрын

    Ultimantis i think it is diffcult to edit multi object

  • @CSPlayerDamon

    @CSPlayerDamon

    3 жыл бұрын

    Was using them for the cards in a card game as well, switched to prefab variants because they are way better. Now I'm only using them for very specific data-oriented things.

  • @kippenegg

    @kippenegg

    3 жыл бұрын

    They've got their positives but as a person for whom the editor lags quite a bit, i don't like making everything there unlike most people

  • @alexgeeves7096
    @alexgeeves7096 Жыл бұрын

    what a great voice this narrator has

  • @Maskedmous
    @Maskedmous3 жыл бұрын

    So again it would be nice to see tutorials with Addressables involved and these Scriptable Object projects. Because to me it is quite troublesome. There's a problem with Scriptable Objects being in the scene and when they're on addressable prefabs. Mixing addressable prefabs and scenes. How to work around the issues that get involved.

  • @IndieFist

    @IndieFist

    11 ай бұрын

    nice question, have you found it a good implementation with scriptable + addressables in this two years?

  • @TurboMakesGames
    @TurboMakesGames3 жыл бұрын

    Scriptable objects are great and I use them quite a bit in my projects . One you start using them, you'll never go back 😊 Just be careful and don't use them for _everything_ 😁😁

  • @GIAGreenFire

    @GIAGreenFire

    3 жыл бұрын

    You can make the majority of a game using them, minus the visuals and audio. But you won't have a game unless you use at least one MonoBehaviour in the scene as a startup script. Unless someone knows of a better way to hook into the game loop.

  • @fenrirab620

    @fenrirab620

    3 жыл бұрын

    How do you handle persist data changed when reloading the game on a specific ScriptableObject

  • @glynwilliams4204

    @glynwilliams4204

    3 жыл бұрын

    We now use prefabs AS scriptable objects. They can do everything that scriptable object do. But also have the benefit of being able to be assembled into hierarchies. Which makes some bits of code just vanish away.

  • @jayc602

    @jayc602

    3 жыл бұрын

    @@glynwilliams4204 Can you go into more details please?

  • @glynwilliams4204

    @glynwilliams4204

    3 жыл бұрын

    @@jayc602 Check out Craig Perko's blogpost and KZread video on this subject. Prefabs can now do exactly the same as scriptable objects. Hold data, run methods without being instantiated. BUT you can also add components and children which is very useful.

  • @falco830
    @falco8302 жыл бұрын

    How do ScriptableObjects differ from NetworkBehavior? I accidentally used ScriptableObjects in my Network game and I think I used them improperly and it made things behave weird in my game between my client and server.

  • @artjom5617
    @artjom56172 жыл бұрын

    u just have to love unity.

  • @darkman237
    @darkman237Ай бұрын

    Will the changed data be the same even in a build? If not, how to correct for it?

  • @Dumbird0
    @Dumbird02 жыл бұрын

    So just want to check. If I had charactors that are connected to a scriptable object with stats in 2 seperate scenes, those stats were changed before scene changed. Would the new stats still show as changed in the new scene.

  • @denisgoodman4492

    @denisgoodman4492

    2 жыл бұрын

    Commonly Scriptableobject doesn't use for data which can be change at Runtime (it changing in "editor mode"). If you store stat which change during play you must use other "objects" (e.g. serializable data stored on disk). Good practice separated data on "const data" (store it in SO) and other data which will changed

  • @milhouse8166
    @milhouse81663 жыл бұрын

    Are scriptable objects supposed to hold data, or are they more of a template which data can be fed into?

  • @MoreNimrod

    @MoreNimrod

    3 жыл бұрын

    In the example used here they contain data that all units or cards share. So in stead of every Archer having a script attached that has some attack behavior and its base speed, hitpoints, it used the Scriptable Object. So all Archer units refer to the Scriptable Objects for those values instead

  • @MEGA_TREE
    @MEGA_TREE2 жыл бұрын

    Amazing

  • @leandroamarillo3262
    @leandroamarillo32623 жыл бұрын

    I never see unity talk about how scriptable objects only persist data during editor and not during real play. I know that it’s not the purpose but the docs aren’t very clear and i’ve seen too many people trying to use it as a way to store game save data. When i first discovered them, reading the docs never clarified that and we got to an advanced state of development thinking it worked that way and you can see in this video comments from people that have fallen into that line of thought

  • @gilgameshcraos1260

    @gilgameshcraos1260

    3 жыл бұрын

    how does it actually work then? My friends and I are working on a project and we realized that we finally are going to need persistent data between scenes and not have scenes and objects that rely on a default setting. they need to be tailor made based upon the data between scenes. What did you all end up doing?

  • @leandroamarillo3262

    @leandroamarillo3262

    3 жыл бұрын

    I you need them to persist ONLY between Scenes you could have an object using DontDestroyOnLoad. We used to have a Singleton for that and we ensured that it wasn’t destroyed between scenes with that api. I’m not working professionally in unity for more than 2 year now so there may be other better ways now, that was worked for our scenario because we had to keep track small state data that was destroyed when you stopped playing. For persistant data we had user preferences that was stored in shared preferences, we had that loaded into the object on start and persisted on stop An we also had to keep some report data that we had made a small ORM (less than 500 lines if i recall correctly) to store it in sqlite

  • @magor7629
    @magor76293 жыл бұрын

    I did not know that changes during runtime persist. Can this be abused to make simplified save files?

  • @HunterSchramm

    @HunterSchramm

    3 жыл бұрын

    Only works in editor afaik

  • @Norbingel

    @Norbingel

    3 жыл бұрын

    That's what I thought before. But changes only persist in the editor. On build, they revert to the starting values on exit so can't be used as save files.

  • @leandroamarillo3262

    @leandroamarillo3262

    3 жыл бұрын

    No, they really should be adressing this somewhere because it’s kinda misleading

  • @Ashley-xb1dz

    @Ashley-xb1dz

    3 жыл бұрын

    @@leandroamarillo3262 could you export then as json and load them back in? Would that help with the save data management? It's seems easy enough as scriptable objects have a built in function for that.

  • @fenrirab620
    @fenrirab6203 жыл бұрын

    On Scriptable Obects, does the data modified in a field persist after closing the game, i want to save changes then load it. For example, i have a List of Entity that tracks its winRate, i want the incremental data to persist. When reloading the game.

  • @leandroamarillo3262

    @leandroamarillo3262

    3 жыл бұрын

    Only in editor, when you run it in your device it wont persist data

  • @fenrirab620

    @fenrirab620

    3 жыл бұрын

    @Servail Catseye does JsonUtility support array? I can't seem to get my array in a Json to print out.

  • @fenrirab620

    @fenrirab620

    3 жыл бұрын

    @Servail Catseye thanks for the quick and understandable reply. I a somewhat good understanding with OOP, is there a good place/video you could recommend me to learn about wrappers. Thanks!

  • @blablafoof
    @blablafoof3 жыл бұрын

    If we spawn a scriptable object and then change the parameters, like the HP, would it change the HP for any existing scriptable objects that has already been spawned?

  • @sindiinbonnienclyde

    @sindiinbonnienclyde

    3 жыл бұрын

    Hopefully I understand your question correctly. If you spawn an instance and change fields then when existing playmode, the so is actually destroyed. If in play mode the so is created through the process of using asset data base and saved to disc, any changes will persist after. And finally, if you modify an existing do in play mode it keeps its values unless you write custom code to prevent this....some of this is explained in the video.

  • @MrFrostCA

    @MrFrostCA

    3 жыл бұрын

    Depend on the way you change the parameters. In game (During gameplay, lets say if you shoot an enemy zombie lowing its hp), no it doesnt change parameters on already spawned objects(On other zombies in this case). In editor, yes. the changes are globally. Scriptable objects are like Interfaces, but cooler. way cooler

  • @blablafoof

    @blablafoof

    3 жыл бұрын

    @@MrFrostCA Cool! I remembered using scriptable objects in the past (like 4-5 years ago) and it was sort of strange to use. When I created the scriptable object in Editor, then had something instantiated with it, the parameters were being changed in the file itself (it was how much gold each town had, and their income). I don't know if I did something wrong, or if it was something like a precursor to scriptable objects. I'll try returning to try it out.

  • @majnoon1935
    @majnoon19353 жыл бұрын

    guys i had a question please help : do game developer needs to learn VFX or VFX maker is a different with coder? and does VFX need any coding? cuase i hate graphic works and love coding tnx for you help and sorry for my bad grammar .

  • @lootgodamn5721

    @lootgodamn5721

    3 жыл бұрын

    depends, I'm a gamedev and don't know a bit about VFX except the unity particle system :) It's not needed for people like us. Good luck with your career bro

  • @scratchy996
    @scratchy9963 жыл бұрын

    Did someone manage to get Unity Royale Project working ? I tried on different 2019 and 2020 Unity versions and couldn't make it work.

  • @denisgoodman4492

    @denisgoodman4492

    2 жыл бұрын

    Was updated to 2020.3

  • @warlockCommitteeMeeting
    @warlockCommitteeMeeting3 жыл бұрын

    What is the best way to save scriptable objects as a binary for a save system?

  • @glynwilliams4204

    @glynwilliams4204

    3 жыл бұрын

    Scriptable object are already serialised because they exist as assets. If they hold live data, you can serialise their contents to a JSON string for saving. Deserialising to pre-existing object requires the overwrite trick.

  • @warlockCommitteeMeeting

    @warlockCommitteeMeeting

    3 жыл бұрын

    @@glynwilliams4204 Thank you for the info. When you say overwrite trick what do you mean please?

  • @fulongfromthegrave
    @fulongfromthegrave3 жыл бұрын

    I kinda prefer a MonoBehaviour equipped with base classes or interfaces as public or private fields over SOs, about 90% of the time: this lets me use constructors, so more runtime flexibility and it makes it easier for me to organise my code. I do use SOs for things like global variables, saves and so on though.

  • @philippschmitz1787
    @philippschmitz17873 жыл бұрын

    Okay, so what's the news? Scriptable Objects are about 2 years old. Or did you change something about them? They're quiet useful tho... but it's very sad that you can't create them in the final build. Would be cool if you could create content by using SOs in the final game. Or is there a way that I just didn't figure out yet?

  • @LuukDomhof

    @LuukDomhof

    3 жыл бұрын

    Since they're 'just' data containers you can 'create' them just like you can create any other data. Simply make your game look for a text file in a directory that contains the JSON output of a ScriptableObject and overwrite it using the JsonUtilities class. As an alternative you could roll your own serialization system for more customizability but for most functionality the default json serializer works just fine. For stuff that doesn't serialize well you can use the BeforeSerialization and AfterDeserialization (Or whatever they're called) callbacks to customize the default serialization behavior.

  • @theapein
    @theapein3 жыл бұрын

    I wish there was easier way to save/load custom binary data from multiple scriptable objects, not much stuff on it on the web, maybe unity team could give some tips

  • @VMEcycle6

    @VMEcycle6

    2 жыл бұрын

    Yeah I had the very same problem and I just found a solution which is kinda pain in the ass: For each scriptable object class, create a class with system.serializable accordingly for its data properties. Then sync all the data into the serializable object at runtime. On save, store serializable into JSON. On load, read from JSON into the serializable object. It might not be the only solution. And may not be the best practice either. But all the tutorials shows like you can just use scriptable object as runtime game database. It actually is not!

  • @ZorrroUK
    @ZorrroUK3 жыл бұрын

    Maybe I'm just too tired right now but I'm not really wrapping my head around some things here. What are the benefits of using scriptable objects over monobehaviours? Specifically, when can I avoid using monobehaviours and what is bad about them?

  • @ostelaymetaule

    @ostelaymetaule

    3 жыл бұрын

    If I understand that correctly, first you will bloat the memory with multiple instances of data if you bind it to a behavior as you create multiple entities during the game, f.ex. The bullets, the scriptable object exists only once. Second, the s.o. is some sort of global state which is the same for multiple scenes, useful for Highscore and networking

  • @glynwilliams4204

    @glynwilliams4204

    3 жыл бұрын

    Conventional monobehaviors have to exist in the scene hierarchy. Scriptable objects behave as assets. This makes them good for manager classes, or as lightweight containers describing things like game events or sound effects.

  • @leo523

    @leo523

    3 жыл бұрын

    The performance

  • @Nokdef

    @Nokdef

    3 жыл бұрын

    Data independency. Plus some extra modularity. You can have your healthbar, your game manager, your health potions and your player all reference a scriptable object that holds a int with the player health, and when you update the value (by using a potion for instance) automatically everything else will be updated immediately. This is specially good for stuff that would use events to keep track of a bunch of data change and to keep this data change modular, like cardgames. I use this also as a mean to do UI stuff. Like a spellDisplayData holder, that has all the info of name, description, icons etc. This helps greatly with localisation and other things. Scriptable objects are great if your game needs to be modular (like a cardgame or a RTS).

  • @ZorrroUK

    @ZorrroUK

    3 жыл бұрын

    @@Nokdef would it be worth using this method for a relatively simple top-down shooter?

  • @hurhurhur123
    @hurhurhur1233 жыл бұрын

    To clarify to everyone asking if you can edit the values at runtime and have it save, think of it like any other prefab. You can only edit and save them in the editor. Any changes you make when playing outside of the editor will not save. You still need to save and load things the same you would as if you had the values on a monobehaviour instead.

  • @MrTutiplengo
    @MrTutiplengo3 жыл бұрын

    Not so much a tutorial, but more of a "why scriptable objects are useful". How do I create a ScriptableObject? How do I reference them from another script? Basic questions I expected to get an answer to. Guess I'll look elsewhere.

  • @ysundawa

    @ysundawa

    2 жыл бұрын

    This is exactly what I thought of, it's a presentation kind of explanation, not a tutorial

  • @ysmstudio9237
    @ysmstudio92373 жыл бұрын

    unity is the best 👌👌👌👌👌👌❤❤❤❤😎😎😎

  • @pagames3d
    @pagames3d3 жыл бұрын

    Every time data changed in run time as say hitCount , when exiting the game in mobile, value don't saves always. So, I use load/save script for S.O to save run time data.

  • @abedanilo

    @abedanilo

    3 жыл бұрын

    It's because when in editor, the same instance of SO is referenced in Play mode and in edit mode , so while Editor is active it will keep all the changes between play sessions and apply that to the binary itself if it's "dirty". While on phone, once SO looses all references, it gets unloaded from RAM. That is why, if you use it i.e. for keeping game options, it will keep them in Editor between scenes/sessions but will not keep them in the built app itself.

  • @leandroamarillo3262

    @leandroamarillo3262

    3 жыл бұрын

    Don’t use it as a method to persist data, it will only bring headaches because during editor mode it will work but it wont persist on a real build

  • @abedanilo

    @abedanilo

    3 жыл бұрын

    @@leandroamarillo3262 It really only depends on how well do you understand serialization and how you code it. If you code it to work, you will not have any problems with persistence. If you had any problems with it, I would like to here some examples?

  • @sinan4651
    @sinan46513 жыл бұрын

    seems logical

  • @dontseemyprofilepicture1292
    @dontseemyprofilepicture12923 жыл бұрын

    Pls don't leave bolt tutorials 🙏🙏

  • @457Deniz457

    @457Deniz457

    3 жыл бұрын

    KZread, Google, Udemy ?^^

  • @gladiumcaeli
    @gladiumcaeli3 жыл бұрын

    Is ECS going to be a thing next year or sometime later?

  • @miloszivkovic6256

    @miloszivkovic6256

    3 жыл бұрын

    in 2025

  • @cffee_

    @cffee_

    3 жыл бұрын

    Milos Zivkovic haha, maybe

  • @thomlaurent
    @thomlaurent3 жыл бұрын

    So you're saying using a MonoBehaviour + a ScriptableObject for its data is the best choice ? What about simplicity 🤔

  • @joeysimon3331
    @joeysimon33313 жыл бұрын

    Hello unity

  • @anesumugiya1534
    @anesumugiya15343 жыл бұрын

    Hey Unity? Your game engine is awesome but can you do us a favour and make updating to newer versions of the engine smoother. I seem to be now getting errors on basic things like Layout and The package Manager. Sure, I managed to fix them but there are very irritating inconveniences.

  • @MrGbison

    @MrGbison

    3 жыл бұрын

    you know.. Unity can read this on youtube.. perhaps you need to ask directly on the forum.. You not alone

  • @anesumugiya1534

    @anesumugiya1534

    3 жыл бұрын

    MrGbison Thanks. I had already put this on the forum, just thought putting it everywhere would help them notice that their updating process isn’t user friendly.

  • @abdou023
    @abdou0233 жыл бұрын

    So, the only difference is memory usage?

  • @MrGbison

    @MrGbison

    3 жыл бұрын

    Read above.. is related for mobile issue?? perhaps?

  • @leo523

    @leo523

    3 жыл бұрын

    For the end user, yes. And will be faster

  • @Phalistafer
    @Phalistafer3 жыл бұрын

    Please post something dedicated to Brackeys. The man has done so much for your Software and deserves some recognition!!

  • @sibasishsahu4275
    @sibasishsahu42753 жыл бұрын

    Is this Clash Royale ? 😁

  • @PrabhuKaranSelvamani
    @PrabhuKaranSelvamani3 жыл бұрын

    So clash royale is made with unity?

  • @migueldomingos4570

    @migueldomingos4570

    3 жыл бұрын

    Nope. They made it from scratch

  • @starrynight3945

    @starrynight3945

    3 жыл бұрын

    Don't be so naïve. It is or it is no. But they could even do more hardest thing, for their game. To be in pioneer it no easy. Not so easy for Unity to make game making accessible though

  • @timurkairatone1312
    @timurkairatone1312 Жыл бұрын

    How to call this object type ? i mean how objects look

  • @tiqosc1809

    @tiqosc1809

    6 ай бұрын

    They look like..... objects

  • @natsuexp_channel
    @natsuexp_channel3 жыл бұрын

    Estas a full unity channel

  • @armanamrazyan6609

    @armanamrazyan6609

    3 жыл бұрын

    yes

  • @jeff5881
    @jeff58812 жыл бұрын

    Usually the tutorials by the companies themselves are the worst. They're either too abstract or lack any implementation details.

  • @clearnandimprove4604
    @clearnandimprove46043 жыл бұрын

    I made a scriptable object for player stats if anyone is interested in checking it out.

  • @misterbeach8826
    @misterbeach88263 жыл бұрын

    Aside from code formatting issues in this video, it is perhaps worth mentioning that although our Unity game is perhaps one of the biggest in the world, we barely use ScriptableObjects. Why? Unity is quite messy and unstable with binary objects. Unity is not good at git with larger teams. ScriptableObjects are a tool, so use it wisely, but limited. If you can, try to get rid of as many editor functions as possible. The less your project depends on the buggy Unity editor (that sometimes removes references, or even decides to conflict meta files after a git merge, especially when your team has devs working on OSX and Win), the more stable your project will be in 2-3 years. It's just too important. So, Unity emphasizes the editor for many reasons, and with it come many features such as ScriptableObject, but if you can, think like an engineer: the editor is not your project. Your game is your project, and the Unity API is fantastic. But the editor is not your project. The editor is just another dependency. So, focus on the strengths of C# and Unity API, and use the editor for basic and obvious stuff. It will cause you less headaches and workarounds.

  • @GuillinCorp

    @GuillinCorp

    3 жыл бұрын

    Thanks for sharing your wisdom

  • @miloszivkovic6256

    @miloszivkovic6256

    3 жыл бұрын

    What would you use instead of scriptable objects? Where would you store static data? Finally what game?

  • @MrKraignos

    @MrKraignos

    3 жыл бұрын

    Thanks for the educated feedback

  • @behnamrax
    @behnamrax3 жыл бұрын

    WHAT?!!!!

  • @theplaymakerno1
    @theplaymakerno13 жыл бұрын

    Uses Visual studio code to demonstrate code and yet Unity does not have an official Unity Debugger!

  • @johndoejr.7180
    @johndoejr.71803 жыл бұрын

    what

  • @user-vq3ev7ef7r
    @user-vq3ev7ef7r Жыл бұрын

    Sa

  • @takkiemon
    @takkiemon3 жыл бұрын

    bruh brackeys just left. the body aint cold yet

  • @kaustubh01_
    @kaustubh01_3 жыл бұрын

    Brackeys 😭😭😭

  • @robertamiller864
    @robertamiller8643 жыл бұрын

    If you make games that are suppose to pay out cash have them pay out. I have been playing Solitaire Real for about 3 weeks and I have only gotten to $19.90. With a $20.00 payout I am wondering how long I need to play to get paid? I got to to $19.90 in about 6 days. I am up to level 342. What level do I need to get to to get the $20.00? If this is not fixed I we spread to NOT play your games!

  • @jde12

    @jde12

    3 жыл бұрын

    Uhh I think you posted this on the wrong channel?

  • @BeardedCatDad
    @BeardedCatDad3 жыл бұрын

    Just an FYI, there is a woman yelling in the background throughout the video.

  • @TobiasSN

    @TobiasSN

    3 жыл бұрын

    No there isn't???

Келесі