Unity Nested Scriptable Objects - Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome in this video i'll show you how to make nested scriptable objects so for that we need two scripts first we'll simply just make one called container let's just call it damage types there we go and the other one we'll just call them staffed again the names are irrelevant it's just so that you will get a better idea of what we can use this for all right so now we have the container and the device time so this is one is going to be the parent and this one is going to be the child or children all right now that the script finally open which simply will remove this and remove mono behavior and put it out with the scriptable object there we go scriptable object we'll also be needing the unity oh using unity editor so we're gonna go unity editor and that we actually need to put inside a hashtag so if unity underscore it and on the other side we're gonna go hashtag uh and if all right so the reason for that is that we are going to have this specific ping this specific thing in the game and anything that has with the unity editor editor we need to tell that it's that should only be in the udt editor meaning when it builds the game it will ignore this part of course we will add other things down the line that we it also will be ignoring all right so next up we are going to make a serialized private list of damage types and we're gonna call it damage types and let's just instantiate it here so we have it all right and let's make a [Music] public so we can get it from outside as well the code all right so now actually needs to do so we can make it oh we'll probably actually need to go back into oh this is the right one yes the damage type and actually make the damage type into a scriptable object or else this will probably not work so scriptable object here we are and this actually also needs to be inside the unit here it also needs to have a unity editor so we're gonna do this and let's actually make it uh no yeah it needs a reference to its container so we're going to go con can i can spell for something right now let's see container damage time that we are i'm just gonna go damn it oh no that was not what i wanted let's just go my container there we go i think that's fine and let's make that also so we can get our hands that and we do not want a set we don't want to accidentally change that in the code and next up let's just make some some you know some fields just to have something let's have a name so name and let's just add a sprite oh yep call that icon let's just google that and again probably also one of those severalized fields there we go and again we don't want to be to be able to change those from outside so we're just gonna remove that next up i think we will probably make an instantiate here so we're gonna make a public void called instantiate oh yeah i'm just trying to copy paste it because instantiate i don't know exactly how to spell it correctly i think that is that's close enough and there we pretty much just want our container in it there we go and we're just gonna go oh no so my container equals my container there we go so here we will instantiate it and again we actually only want that in uh actually when we want that in the editor we don't want that in the game so we actually going to edit inside here well we don't really need this but we might as well add it in alright so next up we will add the possibility no i think this is good enough let's jump over so we can actually make it uh let me just look at my notes quickly there we go actually we also want this here so we're gonna go let's be gone and let's just make some space and we're just gonna call it let's say make new damage type let's just call that and we also wanted to be able to find it outside in the inspector so we gonna use the content menu and just call it make new let's just call that all right so now we need to go damage type let's just call it can we call a demonstrable yes we can all right so that's gonna be a scriptable object because now we need to actually make it scriptable object dot create instant and of course we need to tell it what type it is creating all right so here we actually create the scriptable object now we need to change something in it so the name of the new scriptable object we're just going to call it a new damage type so that is what it will be called outside uh in the unity inspector and we need to we need to call the civilized field here and throw this inside it so it has a reference to its damage container and we need to add it to our list so we're gonna go dot add damage type all right so now we need to do a lot of unity stuff so we're gonna go asset uh data dirt at objective asset and here we are going to add the new damage type and call it this so this one here will be the child and this one here over here is the the parent and next up we need to save what we have done so save asset then we also need to go into the unity editor and actually tell it that it has become dirty and that is a really weird thing to say but that is what unity calls it so first we're gonna go this just gonna duplicate this one here and go damn it type alright so this one should make it sound let's save and jump back out i think this is the one i probably have too many unity things open at once oh yeah we forgot the one of the important things we actually forgot this up here also we can't really actually create one uh what is it it is straight asset menu and then here we need to go isn't it something if you go let me just check if this work if you go create as a menu and double tap ah that didn't work i was just hoping all right so we need to go file name i'm just gonna call it i'm just gonna be lazy and copy paste this down here that will be the name when we created then we also need to find it in the menu so we're gonna go menu dot or let's just go stats i guess and go damage container i think that is fine so let's go back into unity now we should be able to right click and find it so right click stats damage container alright so here we can see our beautiful list there's nothing in it so we can go up over here click and click make new and as you can now see we now have made a new one down here and we could just keep making them but they named the same thing right now and we don't really want that so we're gonna go in and make a function that they can rename themselves so let's just do that we will actually need this thing here again because it is um editor script and this one don't need to be public this can be private i'm just gonna go white and call it rename and it's simply just going to be this dirt name equals underscore name and we're gonna go asset database dot save asset and we also need to set it to be dirty it sounds really weird when you say it out loud dirt set dirty and we will simply add this inside of it and then we will also make our contact menu appear so contact menu and just call it rename to name save that go back into unity and we can now jump over here and let's just edit water we can go up and click rename terrain and as you can see now they're all added we can now rename them uh let's see earth i think let's just make the four elements just to show we can and air here we go and they're all inside here all right so what if you actually want to delete them because right now you said it can't delete them so we need to make a a way to delete them again so let's just jump in here and again that is a unity editor so we actually want this one here so let's just call it delete this you know what let's just call this one here delete this as well and delete this one here and here we actually need to go into our into our container because we need to remove it from the container as well so what did i actually call it in here i call it damage types so we're gonna call damn damage types dot remove and we're gonna go this afterwards we will go on do dot destroy asset immediately and say this or we have to go as a database that save asset so we will destroy it and then we will save the the fact that we have deleted it all right so let's go back into unity and try and let's actually make a new one just because we have our beautiful four elements let's just make two and we can go delete this and we can even rename it and then delete it and as you can see here they are still in here alrighty so what if you just want to delete all of them well let's just quickly make a method for that as well so if we go into our damaged container and just get all of this empty this one out and rename it to delete all let's just also call this delete all all right so in here we need to make of each loop that actually goes the opposite way because when you are removing from the for each loop it will you need to go the other way because if you have 10 and you start from the bottom going one two four three five um and removing along the way well you will get a giant arrow so we just need to change this a little so i is actually equals dirt count so this is what we start on and we actually want to just go i minus minus oh why did we go all the way over there i minus minus and when the minus is bigger than zero oh i forgot to then we uh finished counting okey dokey so let's see so we need to go damage type and just call it tmp equals underscore them is container oh we want the eye inside of it and here we gonna go damage container dirt remove and the reason why we are instantiating while we are adding a reference here first is because we actually want to remove it from the list before we delete it because when it is deleted the well the reference really doesn't exist anymore sometimes you can you don't need to do this sometimes it will it will still remove it and not get error but um for some reason it's like 50 50 in my experience so i have i just did this and i hadn't had an error since so i don't know if it was supposed to do it or sometimes i'm just lucky and then afterwards we simply save the asset and we save and we go back out and we should now be able to delete it all and here we go so now you know how to make scriptable optics nested prefraps not nested scriptable objects i hope this video found you well and then you know like subscribe and all that stuff so thank you for watching
Info
Channel: Kasper Dev Unity
Views: 10,930
Rating: undefined out of 5
Keywords: NestedScriptableObjects, Nested Scriptable Objects, unity Nested Scriptable Objects, nested scriptable objects unity, scriptable objects, unity, unity scriptable objects, Tutorial
Id: 81kyAHy9gUE
Channel Id: undefined
Length: 16min 46sec (1006 seconds)
Published: Mon Aug 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.