Scriptable Objects! Have you used them? They have so many awesome possible uses! 🌐 Have you found the videos Helpful and Valuable? ❤️ Support on Patreon www.patreon.com/unitycodemonkey or get the Game Bundle unitycodemonkey.com/gamebundle.php
You explained it very well. I made a tutorial series for a Turn-Based RPG like Pokemon, where I stored the data of pokemons and their moves using scriptable objects. Now, I can point people who are unfamiliar with it to this video, so they can understand the basics before following my series.
Scriptable Objects can not only store data, they can also used for things like communication between entities. Its often a better alternative to use scriptable objects than to use Singletons (witch you shouldn't use that much, only in really rare circumstances, some say you shouldn't use them at all). Also, ScriptableObjects can contain logic. If you make them abstract, you can use derived scriptable objects to implement the logic of a gameobject. Its more flexible than using different MonoBehaviours and you can hot swap behaviours without destroying and replacing MonoBehaviours.
How can you use them to communicate between different entities? Do you mean through writing to them and observing their change, kind of like an event? Or how is the best way to communicate using scriptable objects?
This is the only tutorial I've seen that actually made a distinction between the Scriptable Object Definition, and the Scriptable Object asset files that are instances of it. Everyone just refers to all of the various files as "Scriptable Objects" which was really confusing to me at first.
One of my many go to Code Monkey videos, you have a lovely repository now of great tips and tutorials that is super helpful. Your voice/manner is also very encouraging and reassuring with confidence and you get to the point quickly. I love how you give just enough info quickly so we can go "oh yeah that's how it worked, I remember now" to also adding more detail. You deserve great things my friend!
I loved how you explained it! It made it very easy to understand! I think I can use Scriptable Objects a little bit more intuitively now; when I first read about them they seemed SO complicated!
Thanks this helped with some data issues I was having when changing scenes. I needed the data to persist through scene change, but I needed it to reset upon starting the game. Seemed like Scriptable Objects are the solution!
That is one approach, just be careful you fully understand how persistence works with regards to scriptable objects. They will act persistent in the Editor but not in a Build unitycodemonkey.com/video.php?v=5a-ztc5gcFw unitycodemonkey.com/video.php?v=CjJNeyyhsKs
Really awesome video and good tip regarding SO are sent by reference. That will definitely save the memory. Cannot wait to see next part about custom editor. That makes scriptable objects ideal for custom Editor tool! Thanks for you job and sharing your experience with us!
No idea, it just sounds good! I like constantly testing and verifying that the code works so I ended constantly running the game and going "yup the code runs!"
@@CodeMonkeyUnity Thank you for the tutorials. I always watch them with my Evernote on the other monitor, so I can take notes. It's a huge help. Good luck with your work!
One quick thing, they can also be other stuff than just data. A scriptable object is pretty much the same as a monobehavior but without an update method
I wish unity could redo the "asset creation context menu" so it would be more like the "add component menu" that you can search and it oly displays 1 tree layer at a time. That would make scriptable objects way much better. I use Odin Inspector, and I found this script that one of the devs of Odin released where It creates a "super list" of all of the scriptable objects regardless of it having a "CreateAssetMenu" attribute. So you can just search it up and create it, much smoother workflow. Also, I'm afraid to click the like button 😬 666 likes lol
@@farfi55 If you're talking about that scriptable object script thing. Yes. I actually had to dig for the original link for a minute. And it turns out there is a list of different custom scripts on their website. odininspector.com/community-tools/540/scriptableobject-creator odininspector.com/community-tools
I have a question, what makes scriptable object more attractive than public properties of the component? They are both editable... the only advantage I see is that scriptable objects could be places in some config folder and designer may not need to search to which object the controller component is assigned (I saved your video and liked in advance, I will watch it tomorrow, sorry if you answered this question within video)
The main point is they are stored as asset files in your project. They have the same type but different data. So a programmer can create the scriptable object definition for a weapon and make the game work with that definition and then a designer can very easily create more weapons by just creating more objects and setting their data. What you're describing would be doable with a Prefab and a script attached to it, but at that point you have exactly a scriptable object but in a more dirty way. In the next video I will cover a use case of adding SCriptable Objects to the Crafting System
@@CodeMonkeyUnity Thank you so much for your awesome videos! I will watch this video and the next one =) So may be I will come back with some clarification questions later!
70% of the projects I've started since learning how to use scriptable objects use scriptable objects for basically every single thing out of the still very small amount of things I did
Please make the video with a custom editor. Maybe you could also make a video with this scriptableobject custom editor to make levels. Like a 32x32 grid system where we can paint levels on the SObject and create the level by reading the data. Like making a texture2d based level editor but one which is dynamic
Yup I covered Custom Editors here th-cam.com/video/bMuTsAma4tk/w-d-xo.html And here th-cam.com/video/rPBISPzmhog/w-d-xo.html I'll be using that in the next video to make a custom editor for the Crafting Recipes. Making a Scriptable Object to hold Level Data would be a great example project, I'll look into it, thanks!
@@bezoro-personal hi ! Thanks a lot for your reply...i was just learning about rogue like generation and hence I got a doubt if it could be implemented in bolt..since bolt became free I just had a thought of using it..anyway thanks for thr reply..
Sure it's possible, if you go the simple route of just having a bunch of premade level sections and randomly placing them to build your level it can be quite easy. If you want to go more complex it becomes more difficult and the more complex you go the easier it becomes to do it through code.
When I use a scriptable object, and change a value (like "isHeld"), then it changes that for the prefab of it, and not for the instance. How do I fix that?
Can you make a video on Graph View? There's basically no videos online on the topic (or at least ones that explain the API step by step) It's the API that shadergraph uses, and it'd be really useful for dialogue systems for example
Check this th-cam.com/users/MertKirimgeriGameDevvideos there are some videos about Graph View they show everything you need to get started. Should be easy enough to create your own dialog editor after watching these videos.
Also,..not sure I want like 80 item objects filling up my project directory. I usually do the excel csv thing. And store new instances of 'item' in a list. I don't understand the big advantages,...yet, to be honest. I guess editing is easier?
If all you have is text then yes using a Excel spreadsheet would be better. But if you have a more complex data structure where you want to store text and images and videoclips and anything else then scriptable objects are very useful. In the next video I'll show a use case of applying this to the Crafting System
@@hawns3212 Just because they force you to use a very specific pattern of returning IEnumerator, doing yield returns and using a GameObject, that's not something I use anywhere else in my codebase
Hi, here is a question of something i can't find. Is there anyway to drag and drop an image INGAME, recognizing the 3d object more closest to the drop site and changing the skin of the object for the imported image?
When you release the mouse, fire a Raycast and if it hits something get that renderer and change the material. You need to break that problem down into simpler parts, first handle dragging and dropping, then identify whats under the mouse, and lastly change the material.
Can you please make some more advanced tutorial in bolt? Like for crafting system or inventory.
4 ปีที่แล้ว +1
Eu gosto dessa prática. Muitos pensam nela como uma forma de facilitar a configuração de objetos, mas como apontado em 7:45, isso é bem útil para ter um melhor uso de memória. Como sempre, um ótimo vídeo.
Hi Im doing a Card game,and I store Magic card(just run the method of that card then it destroy) method by ScriptableObject, but Its ugly to write a if Or switch(just traverse all type of magic card) method in ScriptableObject ,Is any way to just hook different method in inspector like Enum
So many questions! Lol. If it is a reference to the SO,..and three orcs get a sword item SO, but only one Orc uses the sword and decreases its "durability" stat , will that alter the other two sword's durability?
Yes Scriptable Objects are meant for shared data, in your case you would either store the durability in a different way, like as a member variable in each Orc script, or instantiate a new Scriptable Object for each Orc.
@@CodeMonkeyUnity this is exactly why I dont get the point of SOs. Why would I ever want to save every enemy's weapon to disk? Its like a weird niche way of saving your game data if something happens to be an object, yet you'll still have to save everything else in a typical fashion anyways. Another way to look at it is that a SO really wants something to be an object (a sword here), yet in this orc example, you have to remove critical aspects of it like durability from the item and put it somewhere else. This just makes my brain twist in half.
I don't like them that much because they feel like singletons. For instance, in the enemy weapon example you mentioned, if I were to modify the damage of the weapon of a single enemy (weapon curse debuff or something), every other enemy holding that weapon would also be affected. However, just like singletons, if you plan ahead and know in what ways your game might be extended, then you are good to go.
My general rule is to only ever use Scriptable Objects for static data. So in that case I would store the weapon base damage in the SO, but for any modifiers I would store them in the enemy/weapon instance and would not modify the SO at all
@@CodeMonkeyUnity Yeah, that's a nice way of putting it into words and a good example of planning ahead! In my current case, I searched for this video because I was thinking of using SO's to create string managers (one instance to save keys for ES3/PlayerPrefs, another to store tags, and so on). This way, I will be able to keep the codebase more modular, rather than using a MonoBehaviour singleton that can be referenced by any system at any time.
hi code monkey, can you do a tutorial on how to make abilities with scriptable objects that have unique functions? I've seen several videos on youtube but they way everything is set up, each new ability is a new KIND of scriptable object. if you were to have 100+ different skills, it takes up so much space in the editor, it's hard to organize them. because when a SO is made, you cannot go in to override the function, therefore each SO has to be it's separate entity. I've been stuck on this for quite some time now.
If you have custom logic then one option is indeed like that, make a new type of scriptable object that contains the logic for that new skill Alternatively you could have a that takes in a scriptable object, checks the type and does the specific logic for that object. But in that case you then have logic separate from the scriptable object Yet another option is to go with a much more modular system. Make a scriptable object type for each "effect". Like "projectile", "fire", "dealsDamage"; where each of those would have that logic, and then you construct your skills by composing those different scriptable objects in some array inside the main skill scriptable object. I covered a modular character controller that might help point you in that direction th-cam.com/video/mJRc9kLxFSk/w-d-xo.html Or simply use Interfaces with default function implementations, that way you don't need to write tons of code for each SO, just implement the interface, which can make it simpler. But whatever option you choose you are always going to have some amount of complexity if you want hundreds of skills, there's really no special pattern that makes a system like that super simple, just more manageable
What unity are you using? Unity hub? Or some other unity? And where do i have to go to find the script programming place that you are using right now? :D
Serialization is basically taking the scriptable object with all it's data and converting it into a format that is saved. For example JSON serialization converts it into a JSON string. Those functions run before or after that process happens You don't really need to use them unless you're making some really custom logic where you want to process some data in some special way before/after Unity does the default serialization
@@CodeMonkeyUnity can you help me understand it a bit deeper. when does the serialization process happen? is it when we create a scriptableobject in our asset folder? or when its instantiated in the game ? Im using dictionaries and i need to have isrealizationcallbackreceiver to get an id for the SO Im using a SO for my inventory and SO for my inventory items so the id reference changes. it becomes a bit tricky to save scriptable objects within a scriptable objects
Thanks for this awesome video. I have one little question. If i use a scriptable object for an object(for example bottle of water) and i buy three of them in the game. I can't store the amount in the scriptable object ,right? Because then it will overwrite the asset. How would you save the amount of the item? Thanks again for you great videos and i am looking forward to everything on this channel.
You would create an Item class that would hold a reference to the ItemScriptableObject as the type and a simple int amount. Stay tuned for tomorrows video where I will cover exactly that.
What if I want to use a scriptable object to manage something like enemy stats. And one of the stats is health. Should I have the Monobehavior of that specific enemy change its health when taking damage from the player? Or should I create a unique instance of a scriptable object for every enemy and change the health in the scriptable object? Trying to understand the best use for scriptable objects, if they are mostly a reference for monobehavior, or if they are to be written to more often than not.
Personally I like to only use SOs as read-only data containers, so in my case I just don't store the current health on the SO, I only store the starting health or max health. The current health is stored in a normal MonoBehaviour But that's not a requirement, you can use them for read-write data, there is a famous talk all about that pattern th-cam.com/video/raQ3iHhE_Kk/w-d-xo.html&pp=ygULcnlhbiBoaXBwbGU%3D But keep in mind this possible problem th-cam.com/video/5a-ztc5gcFw/w-d-xo.html
Question! I am making a game which has a set of spells. I didn't know of ScriptableObjects beforehand, so what I did is: I created an abstract SpellBase class script (extending monoBehaviour). It contains common attributes between spells, such as name, description, cost, and cooldown, and an abstract void (UseSpell()). For every new spell script, it extends said SpellBase, adds new atts if necessary, and implements the UseSpell() void. Lastly, a SpellManager script, which makes a List out of all Spells, excluding SpellBase, and on certain key presses cycles thtough the list, and when pressing another key, will trigger the selected Spell's UseSpell() void. Is scriptableObject worth extending instead of monoBehaviour? If so, how can I retain this hierarchy without making a drastic change in code?
You can just swap our MonoBehaviour for ScriptableObject and everything will work mostly the same, only difference is functions like Start() and Update() wont be called automatically. Having a Scriptable Object for each spell type and and making Scriptable Objects for each spell action is indeed a valid way to go
@@CodeMonkeyUnity Hey, thanks for your reply! Unfortunately, I have run into a bit of a problem. Scriptable Objects can't reference scene assets, so my healing spell gets a nullPointerException when trying to interact with the healthbarManager script. Any ideas on what should I do?
I am using scriptable objects to create different types of guns and store some data about them. Also, I am using your concept from the interface video to make a IGun interface and have a shoot function in it. The only issue now is how do I make scriptable object have a function that is specific to that gun so that in the main game program, i just need to pass a IGun variable and call the shoot function?
That depends on how you handle shooting. Is it spawning a bullet prefab? If so you can store it in the scriptable object. Or do you need to do some complex logic that is not just data? If so then you need to write that code somewhere, maybe do a switch on a WeaponType run that code. It all depends on if you can abstract your shooting logic so that it is fully data driven.
@@CodeMonkeyUnity I use raycasts to do shooting and each gun has a different shoot method depending on different logic that is related to their data such as range, fire rate, is automatic, etc. Currently I have a unity event in my scriptable object to which I have linked each of the shoot functions of the gun but I was wondering if there is a better way to do this
The only things that annoys me is how they keep the runtime changes when running on editor. Changes dissapear after restarting unity but sometimes is a hustle specially if youre using Unity Collab
The main point is that it's an asset stored in your project files. It can be used for data but it can also hold logic, you can add any type of functions you want. I'll cover that a bit in the next video when I add Scriptable Objects to the Crafting System.
Yeah, I still don't understand the advantage over the added complexity. I don't understand what problem SO's fix besides being able to let non programmers mess with item stats in the UI or something.
Is it possible to nest scriptable objects? For example I am working on weapon rarity in my game. So would it make sense to have a scriptable object for each type of weapon rarity? Legendary vs Common weapons vs any other rarity. I want all weapons of the same rarity to have certain things in common, like the weapon card and color base. Should those be scriptable objects that I then drag onto each weapon scriptable object? Or what would be the best way to set that up?
Yup you can make a scriptable object to define the rarity and a weapon scrpitable object that has a field for that rarity. That would be a good way to do it.
Please correct me if I am wrong: so the benefit of scriptable objects is suppose I have and an enemy script that is attached to each enemy in my game. That script will have data like sprites, animations, etc which are the same for all enemies but because each script is attached to a gameobject, it will create duplicates of that data. However, with scriptable objects, I can create only one container for that data and use that to reference the data in each enemy script. That will in turn save memory. Correct?
It's definitely a good idea to use stack overflow to help you solve your problems, but when you find the solution don't just blindly copy it. Instead take the time to understand why it works.
CodeMonkey: Can I use scriptable objects to change your simple SpriteAnimator animations at runtime. If not how could I dynamically change de sprites that can be played by the SpriteAnimator? Let say i have idle and walk animations for a unit and play them with the simple Sprite Animator from your video but i want to change the sprites of each animation at runtime to show other unit skin
Sure, that sprite animator is just an array of Sprites so you can store the array of sprites in the ScriptableObject and modify the sprite animator to read the array from the scriptableobject instead of its own field.
@@CodeMonkeyUnity I would like to create something similar to what you do in Simple Turn Based RPG of changing the sprites and animations on runtime. Thanks for answering. I really like your tutorials
So a couple of questions... 1) Does scriptable objects ONLY contain data? Meaning they can't run any method calls on their own... if so, 2). Can scriptable objects be useful in conjunction with ECS?
They can have methods as well, I'll cover an example of that in the next video when I add them to the crafting system. Sure, they can be used in ECS, you just need to grab the reference somehow and then you can use them for whatever you want. Although keep in mind they are objects used by reference, not value structs.
In my opinion scriptable object is just Data based I don't even know why they called scriptable object But i discover recently the nested scriptable object and I'm curious what is the difference and how this new type I will be useful
Yup scriptable objects are the exception, the reason being because I only ever use them as read-only data containers, I never modify them. However scriptable objects do not enforce that rule, that's just a personal rule that I follow, if it's public you can write to it which might break all sorts of things. So if you don't trust yourself to manually follow that rule or if you work as part of a team and aren't sure if everyone is going to follow it, then you can indeed make them private and expose Get() functions like for normal fields.
Can you make a video about the TreeView Editor with basic editing features (like undo/redo and drag&drop to move the nodes up/down). Or can someone post me a link to some other video which shows these features, because I couldn't find any. Im not even sure about the current TreeView situation because it looks like they will make a new TreeView with the new UIElements API, but im not sure if it is already out or not, because I asked in the Unity forum and they sent me github links which are either dead or private and I didn't get any other answer from them yet.
Hello everyone Tell me how to make it easier and more practical: data Exchange between scripts. For example: Get position(). Create a script containing all the others-inheritance - get-set...? Use interfaces for each necessary function ? Or are there other options ?
You could implement an interface, IHasPosition then implement GetPosition() => transform.position That's what I used in some scripts on Battle Royale Tycoon
Really depends on the situation. For example if you have tons of duplicated memory in use and you replace that with Scriptable Object references then yes. But in general they are not necessarily more performant by default, it all depends on what you're doing and your implementation.
I have seen a bunch of stuff about scriptable objects and... I don't fucking get it. Like why should I save that as an scriptable object instead of a prefab? You save memory and it's supposed to be easier to use? How? I don't get it. Let's say you want to have a bunch of items that just use a "weapon" class, so they have like name, damage and speed. That seems exactly the use case for a scriptable object. But I could just create a Monobehaviour for that and I would save an object with that script and some default data as a prefab. Why it is better to use a scriptable object there? You are just passing by the same amounts of references, you are either searching for a prefab of that script or the scriptable object. I don't see how you are using any duplicate data there.
A prefab doesn't define a "type", it defines an "object". So while technically you can do that it's the same thing as how you can hammer a nail with a proper hammer or with your fist. Both will work but you should really use the proper tool for the job.
Scriptable Objects! Have you used them? They have so many awesome possible uses!
🌐 Have you found the videos Helpful and Valuable?
❤️ Support on Patreon www.patreon.com/unitycodemonkey or get the Game Bundle unitycodemonkey.com/gamebundle.php
After this video i will use them at 100%. Nice video like
Hey, I saw that you are online. Please make a series on C# for Unity in which you may tell about commands like addforce etc. Please make a playlist.
You explained it very well. I made a tutorial series for a Turn-Based RPG like Pokemon, where I stored the data of pokemons and their moves using scriptable objects. Now, I can point people who are unfamiliar with it to this video, so they can understand the basics before following my series.
Scriptable Objects can not only store data, they can also used for things like communication between entities.
Its often a better alternative to use scriptable objects than to use Singletons (witch you shouldn't use that much, only in really rare circumstances, some say you shouldn't use them at all).
Also, ScriptableObjects can contain logic.
If you make them abstract, you can use derived scriptable objects to implement the logic of a gameobject.
Its more flexible than using different MonoBehaviours and you can hot swap behaviours without destroying and replacing MonoBehaviours.
How can you use them to communicate between different entities? Do you mean through writing to them and observing their change, kind of like an event? Or how is the best way to communicate using scriptable objects?
This is the only tutorial I've seen that actually made a distinction between the Scriptable Object Definition, and the Scriptable Object asset files that are instances of it.
Everyone just refers to all of the various files as "Scriptable Objects" which was really confusing to me at first.
🌍 Get Code Monkey on Steam!
👍 Interactive Tutorials, Complete Games and More!
✅ store.steampowered.com/app/1294220/
Duuuuuude, firstly you save me with your DOTS videos, now you do with this one!
Muuuuch love for you!
I'm really going to have to rethink how my rpg engine handles characters and items after watching this :D
Yes. This. I always find a new way to refactor everything and If I can manage the transition it always makes further extension easier.
But I've never managed the transition successfully. Something always ceases to work and have to reimplement.
I started using them for everything. It makes everything so much easier.
Yup, sounds perfect for player statistics, quests, inventory, loottables and so on :D
One of my many go to Code Monkey videos, you have a lovely repository now of great tips and tutorials that is super helpful. Your voice/manner is also very encouraging and reassuring with confidence and you get to the point quickly. I love how you give just enough info quickly so we can go "oh yeah that's how it worked, I remember now" to also adding more detail. You deserve great things my friend!
Thanks for the kind words! I'm glad my videos have helped you!
I loved how you explained it! It made it very easy to understand! I think I can use Scriptable Objects a little bit more intuitively now; when I first read about them they seemed SO complicated!
Man you're really doing great job!!!You are using your time and skills to make our journey easy.Huge Respect and love for you.🤗
Thanks! I'm glad you like the videos!
Still the best video on this topic to be found anywhere.
Thanks this helped with some data issues I was having when changing scenes. I needed the data to persist through scene change, but I needed it to reset upon starting the game. Seemed like Scriptable Objects are the solution!
That is one approach, just be careful you fully understand how persistence works with regards to scriptable objects. They will act persistent in the Editor but not in a Build
unitycodemonkey.com/video.php?v=5a-ztc5gcFw
unitycodemonkey.com/video.php?v=CjJNeyyhsKs
I've never worked with scriptable objects. I would say let's expand our horizon! :)
Oh I waited so long for this!😊
Definitely gonna give this a try some day. Thanks, very useful video, as always.
Thank you for this! I have been binge-watching all your videos.
I hope you liked them! Thanks!
your videos are a huge help to my videogame, ill try to support in every way i can.
Thank you!
Cool! As always. We are looking forward to the next video.
Really awesome video and good tip regarding SO are sent by reference. That will definitely save the memory. Cannot wait to see next part about custom editor. That makes scriptable objects ideal for custom Editor tool! Thanks for you job and sharing your experience with us!
Yes but this actually a bad thing if you want to be able to enhance an item or ability only for one player or enemy, not all of them
the cleanest explanation and demo, thank you!
I love your videos. Simple you are the best.
I love your videos man!! How come you like saying "yup" so much?
No idea, it just sounds good! I like constantly testing and verifying that the code works so I ended constantly running the game and going "yup the code runs!"
@@CodeMonkeyUnity Thank you for the tutorials. I always watch them with my Evernote on the other monitor, so I can take notes. It's a huge help. Good luck with your work!
One quick thing, they can also be other stuff than just data. A scriptable object is pretty much the same as a monobehavior but without an update method
Yup, I plan to explore using Scriptable Objects for handling logic in a future video
i can't wait for the steam app!!!!
Great video, if you use "will not/will" instead of "wont" it will make it even better
Watching this video, I can't help but think of well this would apply to RPGs
Yup, RPGs are full or data so this is extremely useful
Thanks. I really needed a good tutorial/ lesson. And you alwalys ( or almost alwalys) do so.
I wish unity could redo the "asset creation context menu" so it would be more like the "add component menu" that you can search and it oly displays 1 tree layer at a time. That would make scriptable objects way much better.
I use Odin Inspector, and I found this script that one of the devs of Odin released where It creates a "super list" of all of the scriptable objects regardless of it having a "CreateAssetMenu" attribute. So you can just search it up and create it, much smoother workflow.
Also, I'm afraid to click the like button 😬 666 likes lol
Yeah that menu does start to become massive as you add more packages, making it like the component menu would be great
can you link please?
@@farfi55 If you're talking about that scriptable object script thing. Yes.
I actually had to dig for the original link for a minute. And it turns out there is a list of different custom scripts on their website. odininspector.com/community-tools/540/scriptableobject-creator
odininspector.com/community-tools
I have a question, what makes scriptable object more attractive than public properties of the component? They are both editable... the only advantage I see is that scriptable objects could be places in some config folder and designer may not need to search to which object the controller component is assigned (I saved your video and liked in advance, I will watch it tomorrow, sorry if you answered this question within video)
The main point is they are stored as asset files in your project. They have the same type but different data. So a programmer can create the scriptable object definition for a weapon and make the game work with that definition and then a designer can very easily create more weapons by just creating more objects and setting their data.
What you're describing would be doable with a Prefab and a script attached to it, but at that point you have exactly a scriptable object but in a more dirty way.
In the next video I will cover a use case of adding SCriptable Objects to the Crafting System
@@CodeMonkeyUnity Thank you so much for your awesome videos! I will watch this video and the next one =) So may be I will come back with some clarification questions later!
@@CodeMonkeyUnityah this definitely makes a ton of sense
70% of the projects I've started since learning how to use scriptable objects use scriptable objects for basically every single thing out of the still very small amount of things I did
What keyboard do you use? Or at least what color keys. The key sound is very good XD
Not sure, I've had it for 10+ years, it's a Samsung something
one from of bests channels
thank you so much new thing added to my back pack
Fantastic Tutorial!
Please make the video with a custom editor. Maybe you could also make a video with this scriptableobject custom editor to make levels. Like a 32x32 grid system where we can paint levels on the SObject and create the level by reading the data. Like making a texture2d based level editor but one which is dynamic
Yup I covered Custom Editors here th-cam.com/video/bMuTsAma4tk/w-d-xo.html
And here th-cam.com/video/rPBISPzmhog/w-d-xo.html
I'll be using that in the next video to make a custom editor for the Crafting Recipes.
Making a Scriptable Object to hold Level Data would be a great example project, I'll look into it, thanks!
I am a designer myself, so I just clicked it.
(laughing noises here) WHAT A GOOD COMEDIAN! 10 OUT OF 10!
Hey! Is it possible to create stuff like rogue like generation using bolt? If yes, it would be cool if you could make a tutorial on it!
@@bezoro-personal hi ! Thanks a lot for your reply...i was just learning about rogue like generation and hence I got a doubt if it could be implemented in bolt..since bolt became free I just had a thought of using it..anyway thanks for thr reply..
Sure it's possible, if you go the simple route of just having a bunch of premade level sections and randomly placing them to build your level it can be quite easy.
If you want to go more complex it becomes more difficult and the more complex you go the easier it becomes to do it through code.
@@CodeMonkeyUnity thanks a lot sir! You have replied exactly what I had wanted to know😊( about which could be preferred)...Again thanks a lot!
When I use a scriptable object, and change a value (like "isHeld"), then it changes that for the prefab of it, and not for the instance. How do I fix that?
You can make video about ScriptableObject + Tile map , Please!
Can you make a video on Graph View? There's basically no videos online on the topic (or at least ones that explain the API step by step)
It's the API that shadergraph uses, and it'd be really useful for dialogue systems for example
Check this th-cam.com/users/MertKirimgeriGameDevvideos there are some videos about Graph View they show everything you need to get started. Should be easy enough to create your own dialog editor after watching these videos.
Also,..not sure I want like 80 item objects filling up my project directory. I usually do the excel csv thing. And store new instances of 'item' in a list. I don't understand the big advantages,...yet, to be honest. I guess editing is easier?
If all you have is text then yes using a Excel spreadsheet would be better.
But if you have a more complex data structure where you want to store text and images and videoclips and anything else then scriptable objects are very useful.
In the next video I'll show a use case of applying this to the Crafting System
By any chance are you going to make a IEnumerator tutorial? either way, thanks a lot, I've learn a lot from your videos :)
I'm usually not a fan of Coroutines but it is a subject I should probably cover sometime
@@CodeMonkeyUnity Why are you not a big fan of them? Is it a specific reason or just habit?
@@hawns3212 Just because they force you to use a very specific pattern of returning IEnumerator, doing yield returns and using a GameObject, that's not something I use anywhere else in my codebase
Hi, here is a question of something i can't find.
Is there anyway to drag and drop an image INGAME, recognizing the 3d object more closest to the drop site and changing the skin of the object for the imported image?
When you release the mouse, fire a Raycast and if it hits something get that renderer and change the material.
You need to break that problem down into simpler parts, first handle dragging and dropping, then identify whats under the mouse, and lastly change the material.
Do you mean drag & drop the image ingame from for example a ingame menu or from the outside of the game for example from the PC desktop or folder?
@@r1pfake521 Exactly
@@CodeMonkeyUnity Thanks for the answer, i'll try that part, but idk how the program will recognize the image and import it :(
Can you please make some more advanced tutorial in bolt? Like for crafting system or inventory.
Eu gosto dessa prática. Muitos pensam nela como uma forma de facilitar a configuração de objetos, mas como apontado em 7:45, isso é bem útil para ter um melhor uso de memória. Como sempre, um ótimo vídeo.
Are you not going to make bolt tutorials
Yup, I'm working on more Bolt videos
Hi Im doing a Card game,and I store Magic card(just run the method of that card then it destroy) method by ScriptableObject, but Its ugly to write a if Or switch(just traverse all type of magic card) method in ScriptableObject ,Is any way to just hook different method in inspector like Enum
So many questions! Lol. If it is a reference to the SO,..and three orcs get a sword item SO, but only one Orc uses the sword and decreases its "durability" stat , will that alter the other two sword's durability?
Yes Scriptable Objects are meant for shared data, in your case you would either store the durability in a different way, like as a member variable in each Orc script, or instantiate a new Scriptable Object for each Orc.
@@CodeMonkeyUnity this is exactly why I dont get the point of SOs. Why would I ever want to save every enemy's weapon to disk? Its like a weird niche way of saving your game data if something happens to be an object, yet you'll still have to save everything else in a typical fashion anyways.
Another way to look at it is that a SO really wants something to be an object (a sword here), yet in this orc example, you have to remove critical aspects of it like durability from the item and put it somewhere else. This just makes my brain twist in half.
What is the library (using CodeMonkey.utils) which is seen in many videos? How did you create? Is there a video on it?
There's no video but you can download the complete package with all the source code and inspect it all yourself
I don't like them that much because they feel like singletons. For instance, in the enemy weapon example you mentioned, if I were to modify the damage of the weapon of a single enemy (weapon curse debuff or something), every other enemy holding that weapon would also be affected.
However, just like singletons, if you plan ahead and know in what ways your game might be extended, then you are good to go.
My general rule is to only ever use Scriptable Objects for static data. So in that case I would store the weapon base damage in the SO, but for any modifiers I would store them in the enemy/weapon instance and would not modify the SO at all
@@CodeMonkeyUnity Yeah, that's a nice way of putting it into words and a good example of planning ahead!
In my current case, I searched for this video because I was thinking of using SO's to create string managers (one instance to save keys for ES3/PlayerPrefs, another to store tags, and so on). This way, I will be able to keep the codebase more modular, rather than using a MonoBehaviour singleton that can be referenced by any system at any time.
hi code monkey, can you do a tutorial on how to make abilities with scriptable objects that have unique functions?
I've seen several videos on youtube but they way everything is set up, each new ability is a new KIND of scriptable object.
if you were to have 100+ different skills, it takes up so much space in the editor, it's hard to organize them.
because when a SO is made, you cannot go in to override the function, therefore each SO has to be it's separate entity. I've been stuck on this for quite some time now.
If you have custom logic then one option is indeed like that, make a new type of scriptable object that contains the logic for that new skill
Alternatively you could have a that takes in a scriptable object, checks the type and does the specific logic for that object. But in that case you then have logic separate from the scriptable object
Yet another option is to go with a much more modular system. Make a scriptable object type for each "effect". Like "projectile", "fire", "dealsDamage"; where each of those would have that logic, and then you construct your skills by composing those different scriptable objects in some array inside the main skill scriptable object.
I covered a modular character controller that might help point you in that direction th-cam.com/video/mJRc9kLxFSk/w-d-xo.html
Or simply use Interfaces with default function implementations, that way you don't need to write tons of code for each SO, just implement the interface, which can make it simpler.
But whatever option you choose you are always going to have some amount of complexity if you want hundreds of skills, there's really no special pattern that makes a system like that super simple, just more manageable
What unity are you using? Unity hub? Or some other unity? And where do i have to go to find the script programming place that you are using right now? :D
Unity Hub is simply the program to manage all your Unity versions and projects, I'm using 2019.4
For the code I'm using Visual Studio Community
@@CodeMonkeyUnity thank you!
Is this possible to be made in say like roblox? which uses LUA
what does onbeforeserialization/onafterserialization mean in scriptableobjects? i dont understand the whole concept of serialization
Serialization is basically taking the scriptable object with all it's data and converting it into a format that is saved. For example JSON serialization converts it into a JSON string.
Those functions run before or after that process happens
You don't really need to use them unless you're making some really custom logic where you want to process some data in some special way before/after Unity does the default serialization
@@CodeMonkeyUnity can you help me understand it a bit deeper. when does the serialization process happen? is it when we create a scriptableobject in our asset folder? or when its instantiated in the game ?
Im using dictionaries and i need to have isrealizationcallbackreceiver to get an id for the SO
Im using a SO for my inventory and SO for my inventory items so the id reference changes.
it becomes a bit tricky to save scriptable objects within a scriptable objects
Thanks for this awesome video. I have one little question. If i use a scriptable object for an object(for example bottle of water) and i buy three of them in the game. I can't store the amount in the scriptable object ,right? Because then it will overwrite the asset. How would you save the amount of the item? Thanks again for you great videos and i am looking forward to everything on this channel.
You would create an Item class that would hold a reference to the ItemScriptableObject as the type and a simple int amount.
Stay tuned for tomorrows video where I will cover exactly that.
What if I want to use a scriptable object to manage something like enemy stats. And one of the stats is health. Should I have the Monobehavior of that specific enemy change its health when taking damage from the player? Or should I create a unique instance of a scriptable object for every enemy and change the health in the scriptable object? Trying to understand the best use for scriptable objects, if they are mostly a reference for monobehavior, or if they are to be written to more often than not.
Personally I like to only use SOs as read-only data containers, so in my case I just don't store the current health on the SO, I only store the starting health or max health. The current health is stored in a normal MonoBehaviour
But that's not a requirement, you can use them for read-write data, there is a famous talk all about that pattern th-cam.com/video/raQ3iHhE_Kk/w-d-xo.html&pp=ygULcnlhbiBoaXBwbGU%3D
But keep in mind this possible problem th-cam.com/video/5a-ztc5gcFw/w-d-xo.html
Question! I am making a game which has a set of spells. I didn't know of ScriptableObjects beforehand, so what I did is: I created an abstract SpellBase class script (extending monoBehaviour). It contains common attributes between spells, such as name, description, cost, and cooldown, and an abstract void (UseSpell()). For every new spell script, it extends said SpellBase, adds new atts if necessary, and implements the UseSpell() void. Lastly, a SpellManager script, which makes a List out of all Spells, excluding SpellBase, and on certain key presses cycles thtough the list, and when pressing another key, will trigger the selected Spell's UseSpell() void. Is scriptableObject worth extending instead of monoBehaviour? If so, how can I retain this hierarchy without making a drastic change in code?
You can just swap our MonoBehaviour for ScriptableObject and everything will work mostly the same, only difference is functions like Start() and Update() wont be called automatically.
Having a Scriptable Object for each spell type and and making Scriptable Objects for each spell action is indeed a valid way to go
@@CodeMonkeyUnity Hey, thanks for your reply! Unfortunately, I have run into a bit of a problem. Scriptable Objects can't reference scene assets, so my healing spell gets a nullPointerException when trying to interact with the healthbarManager script. Any ideas on what should I do?
I am using scriptable objects to create different types of guns and store some data about them. Also, I am using your concept from the interface video to make a IGun interface and have a shoot function in it. The only issue now is how do I make scriptable object have a function that is specific to that gun so that in the main game program, i just need to pass a IGun variable and call the shoot function?
That depends on how you handle shooting. Is it spawning a bullet prefab? If so you can store it in the scriptable object.
Or do you need to do some complex logic that is not just data? If so then you need to write that code somewhere, maybe do a switch on a WeaponType run that code.
It all depends on if you can abstract your shooting logic so that it is fully data driven.
@@CodeMonkeyUnity I use raycasts to do shooting and each gun has a different shoot method depending on different logic that is related to their data such as range, fire rate, is automatic, etc.
Currently I have a unity event in my scriptable object to which I have linked each of the shoot functions of the gun but I was wondering if there is a better way to do this
3nd like 3rd view 3rd comment and 3rd party...😆😆😆
Bro how to patch an app using lucky patcher? Plz tell me if any one knows.
That's a pretty complex topic, you should probably let someone else like Steam or the AppStore handle versioning and updates.
The only things that annoys me is how they keep the runtime changes when running on editor. Changes dissapear after restarting unity but sometimes is a hustle specially if youre using Unity Collab
So it’s just like a struct or class with just member variables and no methods?
The main point is that it's an asset stored in your project files.
It can be used for data but it can also hold logic, you can add any type of functions you want. I'll cover that a bit in the next video when I add Scriptable Objects to the Crafting System.
Yeah, I still don't understand the advantage over the added complexity. I don't understand what problem SO's fix besides being able to let non programmers mess with item stats in the UI or something.
Is it possible to nest scriptable objects? For example I am working on weapon rarity in my game. So would it make sense to have a scriptable object for each type of weapon rarity? Legendary vs Common weapons vs any other rarity. I want all weapons of the same rarity to have certain things in common, like the weapon card and color base. Should those be scriptable objects that I then drag onto each weapon scriptable object? Or what would be the best way to set that up?
Yup you can make a scriptable object to define the rarity and a weapon scrpitable object that has a field for that rarity. That would be a good way to do it.
So they aren't really designed for setting up references between objects?
Depends if the object exists in the scene or as a prefab, you can reference prefabs since those are not connected to any scene
Hi @CodeMonkey
I tried to register on your site, the sending configuration email does not work please check
Please correct me if I am wrong: so the benefit of scriptable objects is suppose I have and an enemy script that is attached to each enemy in my game. That script will have data like sprites, animations, etc which are the same for all enemies but because each script is attached to a gameobject, it will create duplicates of that data.
However, with scriptable objects, I can create only one container for that data and use that to reference the data in each enemy script. That will in turn save memory. Correct?
Yes, although not everything stored in a MonoBehaviour will be duplicated, only value types th-cam.com/video/KGFAnwkO0Pk/w-d-xo.html
Do you think it's a good idea for a beginner to copy code from stack overflow until you learn them?
It's definitely a good idea to use stack overflow to help you solve your problems, but when you find the solution don't just blindly copy it. Instead take the time to understand why it works.
Should i use Scriptable Objects when it comes to individual ability of the enemies?
or I use Inheritance instead
Both approaches are valid depending on your particular case. do a quick prototype to test both methods.
@@CodeMonkeyUnity woah ,thanks brother
CodeMonkey: Can I use scriptable objects to change your simple SpriteAnimator animations at runtime. If not how could I dynamically change de sprites that can be played by the SpriteAnimator? Let say i have idle and walk animations for a unit and play them with the simple Sprite Animator from your video but i want to change the sprites of each animation at runtime to show other unit skin
Sure, that sprite animator is just an array of Sprites so you can store the array of sprites in the ScriptableObject and modify the sprite animator to read the array from the scriptableobject instead of its own field.
@@CodeMonkeyUnity I would like to create something similar to what you do in Simple Turn Based RPG of changing the sprites and animations on runtime. Thanks for answering. I really like your tutorials
So a couple of questions...
1) Does scriptable objects ONLY contain data? Meaning they can't run any method calls on their own...
if so, 2). Can scriptable objects be useful in conjunction with ECS?
They can have methods as well, I'll cover an example of that in the next video when I add them to the crafting system.
Sure, they can be used in ECS, you just need to grab the reference somehow and then you can use them for whatever you want. Although keep in mind they are objects used by reference, not value structs.
In my opinion scriptable object is just Data based I don't even know why they called scriptable object
But i discover recently the nested scriptable object and I'm curious what is the difference and how this new type I will be useful
Greetings. How do I reset ScriptableObjects after each play?
You should never modify them so they should never need to be reset.
@CodeMonkeyUnity - In your current tutorials you mention always making things private. Is that not true in a scriptable object?
Yup scriptable objects are the exception, the reason being because I only ever use them as read-only data containers, I never modify them.
However scriptable objects do not enforce that rule, that's just a personal rule that I follow, if it's public you can write to it which might break all sorts of things.
So if you don't trust yourself to manually follow that rule or if you work as part of a team and aren't sure if everyone is going to follow it, then you can indeed make them private and expose Get() functions like for normal fields.
Can you make a video about the TreeView Editor with basic editing features (like undo/redo and drag&drop to move the nodes up/down). Or can someone post me a link to some other video which shows these features, because I couldn't find any. Im not even sure about the current TreeView situation because it looks like they will make a new TreeView with the new UIElements API, but im not sure if it is already out or not, because I asked in the Unity forum and they sent me github links which are either dead or private and I didn't get any other answer from them yet.
I don't understand differance between structs and scriptable objects
A Scriptable Object is an asset that stores data and lives in your project files.
A Struct can store data in memory
Well, kinda shocked to see the .ass extension at the thumbnail xD
Oh yeah I guess in some cases the time overlay will obscure the text
@@CodeMonkeyUnity mmmmm
.ass
ets, Liked and Subscribed!
can i change the data of scriptable objects in run time ?
Yup, but be careful of the issues I mentioned regarding Editor saving vs Standalone saving
Code Monkey how can i change data of them ? I don’t know how to do that
@@giangbuitam4868 Never used SO, but they are simply scripts with public fields... so I assume SOinstanceName.fieldName = newValue; should do the job.
Thanks!
Can you make a game with bolt in unity.
Sure, Bolt is extremely powerful and you can build anything with it
Hello everyone Tell me how to make it easier and more practical: data Exchange between scripts. For example: Get position(). Create a script containing all the others-inheritance - get-set...? Use interfaces for each necessary function ? Or are there other options ?
You could implement an interface, IHasPosition then implement GetPosition() => transform.position
That's what I used in some scripts on Battle Royale Tycoon
@@CodeMonkeyUnity Thanks a lot. I'm still surprised by your superpower to respond to all subscribers)) It probably takes so much time...
Please tutorial for unity particle system 2d and if the video 2 hours I will watch the video
im pretty new to unity i mean by this is posted unity isnt even installed yet! gimme some uhhh idk?
Indonesia here
Is using scriptable objects more performant?
Really depends on the situation. For example if you have tons of duplicated memory in use and you replace that with Scriptable Object references then yes.
But in general they are not necessarily more performant by default, it all depends on what you're doing and your implementation.
Pls help me I'm just a student and know very little (almost nothing) about programming can you help me where to start, I'm just starting so pls help.
Learn the Basics of Unity here th-cam.com/video/E6A4WvsDeLE/w-d-xo.html
And C# Basics here th-cam.com/video/IFayQioG71A/w-d-xo.html
@@CodeMonkeyUnity thanks
Thanks
Why untity not in phone
another level of json file😉.......
HI there folks
i want to become a proffesional indie developer. do you believe me?
Go for it!
@@CodeMonkeyUnity You are best youtuber in world. there is no youtuber answering the comments.
Please Dotween video
1 view :0
Debug.love()
First!
I have seen a bunch of stuff about scriptable objects and... I don't fucking get it. Like why should I save that as an scriptable object instead of a prefab? You save memory and it's supposed to be easier to use? How? I don't get it.
Let's say you want to have a bunch of items that just use a "weapon" class, so they have like name, damage and speed. That seems exactly the use case for a scriptable object. But I could just create a Monobehaviour for that and I would save an object with that script and some default data as a prefab. Why it is better to use a scriptable object there? You are just passing by the same amounts of references, you are either searching for a prefab of that script or the scriptable object. I don't see how you are using any duplicate data there.
A prefab doesn't define a "type", it defines an "object". So while technically you can do that it's the same thing as how you can hammer a nail with a proper hammer or with your fist. Both will work but you should really use the proper tool for the job.
Thanks!