LIVE: Let's talk about Scriptable Objects - Should you use them?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
oh right when i started get a text message from my wife all right perfect way to start off the stream okay so today um today i just wanted to talk to everybody about scriptable objects really so we'll get started in just a few minutes but i wanted to go over um a lot of ways to use scriptable objects uh different things that i didn't know about when i first started using unity with scriptable objects and when i first started i kind of like learned about mono behaviors i learned about scriptable objects and then i kind of just forgot all about scriptable objects because they seemed kind of useless and pointless to me so today i just wanted to go over some kind of interesting and different ways that you can use scriptable objects there are a lot of different tutorials and videos out there and this is kind of just a combination of some of the more interesting and more useful ways that that i like to do or that i like to use scriptable objects but i also wanted to just kind of involve everybody in chat too and see if people had other ideas or other things that they think would be useful for scriptable object uses that maybe i'm not talking about then maybe there's something that's more exciting or more important that i should talk about so after this is all done i'll probably compile it all into a video where i'll kind of break down like step by step exactly what what you could do like the i guess like the step by steps of each individual one but today i just kind of want to go over like what those uses are um how you set them up how they can be kind of useful and again get some ideas from everybody and chat to you on what they think would be other interesting ways to use scriptable objects so um i guess today i got let's just get started so i guess really quickly for anybody who hasn't made a scriptable object i'm going to do the quick like two-minute version of how we make a new one and how that works so if we wanted to create a new scriptable object it's almost like creating a new mono behavior we could just right click and hit create new script and then we'd go into our code editor i'm using writer so i'm just going to start kind of typing in writer to create it instead of going into unity back here and creating a new file so i'll just scroll or zoom in a bit scroll down i'm going to go to the bottom and just create a new class so i'll make like a new public class public class um oh i'll switch to desktop mode so you can see it too that would make a lot more sense right so here i'm in writer and now you can see i'm at the bottom of my shared number file this is just a scriptable object but i'm just going to make a new one real quick just so you can see what it's like to do public class um some scriptable object uh let's let's make this something that's real um let's say it's like a crafting or a harvesting resource right i just it's not a real one but i'm gonna pretend like a realistic example and make it a scriptable object as the base class instead of a mono behavior and then create the little braces so it's a new class or it's uh closed off then i can hit alt enter and just move that over to its own file this is how i create new files so i don't have to tab back and forth and then i'll zoom in and then to use the scriptable object all we have to do is go right above the class add an attribute use the create asset menu and then we do the open parenthesis and we need to put in a menu name which is just where what it's going to show up as in the menu so here i'll just call it harvesting resource and then we have an optional one the file name i'm just going to put it in there too and this is like what you want the new file to be so i'd say like new resource or maybe new harvesting resource right i think that's the default though is going to be new harvesting resource um so it doesn't really make a lot of sense but if you want to change the default that's how we do it and then i'd add in a couple like public or serialized fields for it like maybe it's a um resource type so do like a public string resource type and i might make that an enum instead so like a public um let's make a public resource type resource type watch this one make this into an enum so we'll convert this into a class alt enter create a type and we'll make that type an enum and you'd have like metal would something like that right so we could have a drop down of a different a bunch of different kinds and then maybe like a skill requirement for this harvesting resource so public and minimum skill and then i'd have this as a bit of a an object that i can go create in unity and now assign to a bunch of objects to say that they give out this this resource let me show how we were created and then i'll go into some actual examples that are hooked up so now that i've got this object created or written up this class here i just go into unity go into my project view and i'm gonna go and i already have a scriptable objects folder in here i think oh no i didn't make a generic one i made subfolders for each of my things so i'm just going to go right into the root and right click hit create and right here let's see where is it uh harvesting resource and just click on it and it's created a new harvesting resource you see it down here at the bottom it's got a name new harvesting resource it's got a resource type here that it's a drop down because i picked an enum and then a minimum skill then i could use this to just save off a bunch of different data let's go take a look at um an actual example that i put together though so i'm going to delete that guy that harvesting resource and then i'm going to go look at let's see one of the what did i do what was a good one in here i think maybe items oh look at this so no wait items are not a good example of my hold on hold on hold on hold on okay let me let me think for just a moment because that's like that is i wanted to go over how to create a script real quick and create a scriptable object and the saving content data like that is just one of the things that we can do and i have an example of that like with this recipe here i'll show it real quick but i don't want to get stuck on it too long so i'm going to quickly show it and then we'll jump over to some of the other things that aren't just saving off content data because that's like the simplest thing and that was my example there that i kind of accidentally used when i was creating or how to create one so let's dive into this recipe so if say i wanted to make like a crafting system right and i wanted to have you know some crafting recipes require some number of ingredients they give back some reward if you're successful and then they give back something else maybe if you fail that's what i've set up here so i've got a recipe with a list of ingredients ingredients just linked to items the items here are just very generic very basic i just made an item script i don't think it has anything in it it's literally just an item script you define your item however you want your item to be right but i've got items here an item or or an iron ore and a uh was it an iron bar let me go check that an iron brick and then if you go to recipes look at it again our ingredients are two iron ores as a success reward of make one iron ore ooh that's wrong and a fail of make a brick yeah mix that up but i can change it just take my brick here and make that the reward and fail back to give myself an award and made it a 65 success chance so let's look at that script real quick see what it looks like and then i want to dive into the much cooler things because this is the very basic thing here so here's the recipe you see it's just an oh i said it was a list that i actually made an array of items for my ingredients that could be a list too it would work just the same here's the success reward item the chance and then the fail reward and then to use this recipe would just go through and look at all of my or look at the ingredients required see if i meet them or if i have those and if so then maybe run a random roll against the success chance or something let's let's jump away from this though and go into something that i think is a lot more interesting which is using scriptable objects for shared data across scenes this is one of the coolest and most useful things that you can do with scriptable objects in my opinion it's kind of a replacement or a substitute for using public static or just general static c sharp classes or c sharp um not really classes but fields or properties so the way that this works let's go take a look if we go into our variables folder here actually let's go take a look at an actual variable first i think i set up a very simple one a shared number so let's let's take a peek at this so this is a scriptable object that's got it's let's start with the very basic one but no i'm trying to decide what i want to do here i'm going to go with this one we'll use the shared number here so this shared number is a scriptable object that has an integer value so here you'll see it's just got a public and named value it's got a subtract method an add method and these just modify value and they also call this changed action just so that we can register for an event to notify or to get a call back whenever this number changes so we can use that somewhere else if we want to know when this number changes we can just register for it and get a call back on it so this is literally just a number in a scriptable object with two methods on it we could almost have this be just without these methods here and just be the value in the scriptable object but the events are kind of helpful and you see how that how that comes into play in a moment so if we have a shared number like this right and i go in and i go to my variables folder and i create a shared number like this clicks this game right what i can do now is regardless of what level i'm in i can keep track of the number of times that or the value of this object so let me just shut up with my bad explaining and dive into an actual example i'm going to load up this level one scene and hit play i'll show you how it's wired up and how it works you can see here i've got my shared number there at seven and i can subtract it away it goes down and it goes down to four i can add it goes up to five six seven eight nine ten eleven twelve thirteen whatever right but then i go over to level two and the number stays the same notice the level changed and you'll see how this is all hooked up in just a moment but i can just go up and down change the number up and down and go back to level one and the number stays the same so it's keeping that number across the scenes using a scriptable object using that shared number so i'll show how that works real quick i'll go into my canvas here i'm going to go down to my subtract button and if you look at the subtract button here it's actually not referencing something in the scene if you look at the on click event here it's referencing the variable and it's calling the variables save number dot subtract method so that's literally just modifying this variable whenever we click these buttons let's click on the health here is it was it the health was that the one that i'm using i think i reused health yeah okay so look at the value there you see that it's five and it goes up and down as i hit these buttons but if i click over to level two i still have that same object selected these are also referencing that same thing so in level two if i go down to these buttons i'll look at my add button here and see that because these things are in the project here they're not in a scene i don't have to worry about cross scene references i don't have to have a second scene loaded having a second scene loaded also can be a great idea but for some situations and for a lot of games and well for this right here it makes a lot more sense to just have a scriptable object that's sharing that data where i can access it from across the different scenes one of the other ones that you notice though where's my click i have clicks this game hooked up i don't have it hooked up right now i don't think i have the mana one hooked up yet either but essentially you see that it's just um sharing the value across the whole project instead of in a specific game object and then it's also updating this ui element so let's look at how that ui element works i'm gonna go to my number text here and let's see i have this saved number binding okay um let me take take a quick drink real quick and then i want to dive in um a little bit more there there's some stuff i want to look at the binding the persisting stuff and i'm also setting up passing out round events but i need a drink real quick all right okay okay so let's see so far i've used the shared number and oh no i used the save number i did not use the shared number so let me look at the saved number real quick show you what that looks like and how it's working with this save number binding so the shared number essentially just added and subtracted numbers right but if i stop playing right now and start playing again it was on 14 it's gonna go right back to a 14. if i go up to whatever 20 stop playing start playing again it's going to go right back up to 20. now the way that this is done is with a simple and not not a perfect little hack to just make a single variable save off on its own now in your own big game if you're building out a big game before i show this if you're building out a real big game and you're not just trying to slap this in for a couple things um i would recommend going with a bigger persistent system where you're saving out your game state but if you're not at that point yet um this works great and just kind of solves a lot of little problems so this saved number is very similar to the shared number in fact it's um exactly the same as the shared number inherits from the shared number i just um override oh actually i'm not even using an override properly here it's actually just hiding the subtracts and the ads and then it's setting the player prefs variable in fact let's fix this up real quick let's make this so that they're virtual because there's no reason for this to be wrong so we'll make those both virtual and then we'll go back in here we'll make this override and then we'll just call into the base dot subtract and pass in the amount so the way that this works for anybody that's not familiar with inheritance and overriding methods if we have a base class here that has a subtract method and we make it virtual with that keyword then in the subclasses like the saved number we can override it and then call into the base one so that way we have a new version of the subtract for this save number it kind of overrides or takes over for the shared numbers version of it but then we can call into the base one and have it do its its own work and then do our extra work here so what we're doing here is um actually am i only saving this that's been so i'm actually only saving this in the uh in editor mode right now i disabled it from saving outside of editor mode so um on it oh that's right because it's um in the inspector yes so the problem here is uh on enable and on disable are kind of a pain in the inspector with um where with chair with scriptable objects in general you don't really get these callbacks when you would expect them there's a look up for them if you go look it up um so there's a there's a document that shows when they're called exactly on the documentation but it's not exactly what you would expect like on enable gets called for scriptable objects that are referenced by things in the scene but on disable gets called first so like you go in but that's like in editor mode on disable gets called first so it calls in and with setting it and clearing things out like i said if you have a bigger a bigger game or you have a lot of stuff to persist build your own persistent system and don't just hack in a little saving but that's what this is doing so let's finish this up so i'm going to finish making this ad be an override and then we'll make this just call into base.add which is literally a copy paste of this code i just want to clean it up so that it at least not showing a bad thing to do okay so we subtract we change the amount and then if we're in the editor we save the variable off and then same here if we add if we're in the editor we save the variable off in fact there's no real reason that we couldn't just do that every time i i don't know why i'm not doing that every time but that's making it save off so shut up i'm going to shut up about the saving and i want to dive into the binding now so the binding was on this number text and i just wanted to talk about that because it was referencing that saved number and it's a saved number binding it should probably just be a shared number binding let's open up this save number binding zoom in and take a peek so this thing references a saved number it has a serialized field for a saved number that's that scriptable object that was in the project view and then on enable it just registers for the change then on disable just deregisters for the changed event remember this changed event gets called whenever the amount changes if i go down to the shared number here whenever it changes change to gets called and then that flies back up to our saved number binding calls into handle number changed which just resets our text to the new bag so that's how it just binds up to anything and just make it show in there or make it update without constantly pulling the scripting or descriptive object so that's um i guess really simple number binding obviously we could bind to any type of object it doesn't have to be an integer we can make this like a generic binding where we bind to any type of primitive or any type of object or we could just make up different types of bindings depending on the game now i want to jump into the um the last one that i thought was oh let's jump over to sounds um this is somewhat related and somewhat i don't know i think i want to talk about this on on these npcs let's go into scene three actually first i want to take a real quick peek at chat and see if anybody has any um any cool ideas or other things that i've missed oh look i know there's a lot of a lot of cool things you can do with scriptable objects so i want to jump into um events real quick and then i just want to show a little bit more on the data and how you hook up the data side too so okay i don't see anything um too crazy in there if anybody has any really cool um scriptable object ideas too let me know i definitely want to check them out but first i want to look at these npcs so here i just got an npc scriptable object or an npc script that's a mono behavior and a prefab here the thing has a data object on it and a sound object on it so when you're thinking about like if i were setting up data like how would i actually set this up and break this stuff up so that it's actually usable this is more um kind of the the way that i would see you breaking it up or the way that i break things up myself so if i've got npcs a lot of the time like you know all of your say i'm here i just use goblin wizards and goblin warriors as an example imagine you've got just a goblin game you've got 10 different types of goblins you got a bunch of orcs you got a bunch of different other things and in general for the npcs you want them to kind of be the same right you want all your goblin wizards to be about you want them to be the same you don't want to have a variation in these you i mean you might in your game but most games the the same npc is going to be the same all the time but some of the data is going to be shared like sound data so when people think about this a lot of time they'll go well if i just put it all in the prefab what's the difference of putting it in the prefab versus the scriptable object the biggest benefits are when you can really break some of that data up at least in my opinion where you can break some of the stuff up like sound and just make that reusable so that like the sounds are all the same if i want to use all the same goblin sounds i just drop the goblin sounds on every goblin right but then if i want to use like maybe i want to use a generic wizard setting based on race and i want to kind of mix and match them that i've got you know race based settings and um and class-based settings too so that way i could have like uh i guess another option here would be like having goblin data and wizard data and then having them even combined so i could combine the stats of both of those and make it so i could set up multiple getting a lot of ideas here just kind of thinking on my own of how different things that i could set up with this too but i hopefully kind of get the idea um one thing that kind of sucks with this though is that a lot of the time if you look at scriptable objects like the inspector is not very good so i'm gonna pull up um on i've got an example um scriptable like custom editor that i can show because i think if you're building these things out and like you start to get a more complex scriptable object the the inspector's just gonna suck well what happened to my little uh my background screen that sucks turned off my beautiful scriptable object image went away and get that to turn back on too um somewhere around here i'll find it real quick we'll get that up but um let me just put this up i'm not going to be able to think straight until i get it up there i don't know why no real reason i i don't think i'm ever going to find it either oh there it is there we go drop that up there sorry i'm going to get this um i want to get this scriptable object inspector up for you so you guys can all see it too but i also want to put my my beautiful scriptable object image up today spent like 10 minutes working on oh and now it's massaged and misshapen all right there we go beautiful heart that's that's kind of the limit of my artwork all right so the descriptive object inspector's still loading up so i'm just kind of keeping everybody distracted while it loads but you definitely do want to have some sort of a more complex um if you have a more complex thing where you've got a bunch of data on it like i'm about to show you with something like a quest then you're going to want to put together um i guess an inspector or an editor for it any sec okay this is going to take forever it's uh it's in collaborate so it's going nice and slow let's see what else did i have that i wanted to talk about in here oh the events that's that's the probably the coolest one um okay here i've got my window up so i'm gonna show it and then i'm gonna show the coolest part the events and then we'll go in and see just what everybody else has and other stuff that i i might have missed all right so let's drag all this out of the way and we'll get this one up here and then um let's go find objects i'm gonna get it all ready for you so it's nice and pretty you can see it um oh i gotta open up the correct project though downside of having multiple things open at once very very easy to get get mixed up new window and have multiple rider windows all right so that's up here and put that right around here and close the tabs okay here we go so switch into desktop mode and you can see somewhat of an inspector so here i put together a somewhat simple quest inspector that actually like views all of this scriptable object data so now i can look let's look at one of the um let me find one of the quests outside of that in a normal inspector real quick and show you what it looks like you can see the the the side by side difference of trying to modify a complex scriptable object in just a regular inspector versus a custom one let's go select this tutorial one and go over to that tab and we'll just bring it right over here so here's the normal inspector tab if you want to modify these quests and you see that it's got like it has all of the same data and this is one of one of the things i guess is kind of important to show that when you set these up you can make like this big giant complex scriptable object that stores all kinds of data and it will generally be represented in the inspector it's just that as things get more and more complex you want to make it easier for yourself and your team to work with so i'm going to start to put together these custom inspectors but here you'll see that i've got an inspector for a quest that has a description and here's the class for the quest it's got a description there then it's got a sprite and i can click on this and go pick a sprite just go choose any old sprite and go choose this gem if i want that to be my sprite it's got some number of steps which is this list of steps here so i can expand out each step here and then go look at those let's hit control and click on the step to see the definition of it what voice control not control click's not working there okay well f12 oh i clicked on the wrong spot control click on the other step so here you'll see that the steps have objectives and instructions let's click back over to that and see it so inside my steps i've got objectives and instructions so instructions is just a string of text like for this steps like so whatever this step is kind of like the overview of the the thing that you have to do and then objectives would be like the actual things that you need to go get like maybe you need to go get a flag a boolean flag and that's a scriptable object so it would be like a flag that needs to get set to true or false would probably just be set to true like you completed the tutorial or it could be that you need to get an item that's what the second flag type is set to a flag type of item requires one and i got to get this rifle item here and then we could add in more by hitting plus or we could select them maybe remove this second element the second step by hitting minus or something if we selected it but you can see again it's kind of a pain to modify and edit so you really want to build out some sort of a custom inspector and that's kind of what i've got here now one of the coolest things about this is if i set up this data here in a scriptable object and then everything is referencing it so i've got like my npcs and my ui and stuff all referencing this as a scriptable object then when i save this if i just go in here and make a change to it it actually just live updates in my game i don't need to recompile i don't need to restart i can just have this like actually just show up right away you know if my ui is bound and and it's updating um well i need something to trigger it to let it know that there's an update that there was an event but as soon as i click off or reopen or anything it'll update to the newest stuff i think that's a really cool thing to do um it's a really useful thing um there is one issue that you need to run it that you need to think about though that i think was lightly mentioned in chat too which is that serialization of these scriptable objects while they are serializable is great um and it works really good in the editor and at a time but if you want to save off state like this it's not quite as easy well there's there's one big downside i should say that the biggest one is that the biggest one that i've run into is that if you have a set of serializable things like let's go look at um what was a good one i i guess i don't have a good one in here right now but if this step was an abstract class and i had like two different types of steps like i had a collect step or maybe it was the objectives instead let's say i have the objectives and this was an abstract class instead of a regular class meaning that i can't just have objectives i have to have some subclass of them and maybe i have like kill objective that it has a like it would look like this let me just type it out public class kill objective objective and then it has like a thing to kill or something and then it had another one that was a collect objective or something it won't serialize out um this type when when we when we try to serialize it so you gotta not do that right don't don't you can't use inheritance with um with them so it's kind of a pain there but i haven't really it hasn't been a big issue for me um in the past or in any real thing other than when i forget about that when i restart using scriptable objects um is there anything else with that let me think i don't think i had anything else on the on that side i want to talk about so i want to just i guess jump over to the last thing i wanted to share which was the events and then just dive into chat so let's see here's the window and the events so i've got these game events set up and if you look at um i want to show this blog post too i think it does a really good job of explaining what i want to talk about this one right here so there's getting started with scriptable objects tutorial they talk um a bit about shared content data here but let me scroll down to the event so this is um essentially what they do right here it's it's a really good tutorial um but i always want to run through and explain why it's so good so the re the what it is is you create these scriptable objects and you implement your own version of the observer pattern the observer pattern is what you use with events like c sharp events when you create an event action of some type and then you invoke it or you do the callback on it or when you use a unity event and then you add in the callback into the inspector like on a button or if you've ever added your own unity event so the same kind of thing here we're just doing a kind of a third way of registering up that same pattern where things can listen for something changing and then respond and react when that thing changes so i'm gonna go through um i don't know should i go through their code i guess i think i have the same code just kind of written up here so let's go look at it um game event okay okay here i've added a little bit extra and i'll show that in a second so the commented out stuff is is the extra stuff so here you see i've created the game event it's a scriptable object so we can go in and make a new one and we have these game event listeners and it's just a hash set of listeners a hash that is just a list or a collection that only allows unique ones so if we ever tried to add a listener twice it wouldn't allow us it's essentially think of it it'll work the same as a list just not going to allow duplicates so then we have a register method on it which adds this listener the one that we pass in to the hash set of listeners that's all this is doing it's an expression body method it's the same as writing it out the long way if i change it out to that it's the same thing it's just a shortened down version in the newer versions of c sharp whoops let's undo that go up here alt enter and change it back to an expression body just shortens it up a little bit if we have a one liner then we have a d register method that takes a game event listener and removes it from that list pretty simple and we have an invoke method the invoke method loops through all of the listeners and then calls the raise event method on those listeners then i also have these two commented out ones these are some events that um i don't think i'm gonna dive into right now but essentially if you wanted to be able to do a callback on any game event being registered maybe you have something in code that you don't want to listen for a specific event but like you want to log out every event that happens or you want to um listen for every event because there's some system that can't have references to these things and it just needs to know whenever an event fires off because it's probably going to respond or something then a static thing like this can just be added in you can add in a public static event to your game event class and then invoke that as well so that's just uh that's what that extra commented thing is but let's dive into how the game event listeners work real quick so we have this raise event we have the register and d register right so let's look at how it's registered i'm going to go to register and hit shift f12 go to the invocation of it and zoom in here so we have this game event listener class and this is a model behavior this is how we hook the scriptable object up to the mono behavior it has a unity event and a game event two serialized fields that's it or it's named global event not game event i guess it should be named game event but whatever so in its awake we call the global event or the game events register method and then we pass ourselves in so remember that's how we're adding ourselves to that hash set of listeners on the destroy we deregister so that we remove ourselves from that set of listeners and then on rey's event we literally just invoke our unity event so if i go back over to unity and we look at a game event listener do i have one set up i don't know if i actually set one up in here um did i not set up a game event listener let's set one up so let's say i wanted let's delete all of these goblins go find this goblin oh this goblin has no image um let's go to the canvas let's add something in the ui instead so we'll go here we'll add a new text object i'm going to duplicate this number text move it up here and shrink it down let's make it like a 100 where's that thing at oh that's way too high let's go to 2d mode zoom out hit t get that resized and i'm going to change this text and remove the save number binding so here i think i want to say um number got high enough so that i'm going to do is set up a unity event or an event that's going to trigger that's going to turn this on when this value gets high enough that we think it's high enough so to do that i'll rename this to two high text or high enough text and then we're going to go in and add a component we'll add a game event listener and then in the unity event for the game event listener i hit plus and i'm just going to turn on our text mesh protect so i'll click drag the text mesh protects in here go to text mesh protects you gooey go to enabled words enabled actually let's just change the text okay number got very high watch this we'll do it i'm gonna do it even better and then we'll clear this out let's clear this text to nothing yet so when the number gets very high we'll set the text to say number got very high let's create a game event for that now so right click create a game event we'll call this number dot i and then let's go look at that again real quick let's see we'll go back over to our game event remember our game event needs to be invoked for this to fire off we need something that's actually going to invoke the game event so what i want to do is create maybe a script that checks what the number is when it changes and then if it gets high enough um actually you know what i think instead of number got high i want to do a number changed no don't do number change sorry i'm just trying to think through what i want to do here because if i i can address let's add it in so we got number got high let's add this in as the event right so what i'm going to do is fire off this event whenever the the number itself gets very high where's the number itself at so the number is on here let's go select it let's select the number text and find the reference and we're using the player health yeah i kind of mixed things up because i named things weird so i named this player health and it's an it's actually like our shared number um so when this thing changes what i want to do is check to see if the value got high enough and if it got high enough then fire off that other event so let's add in a new empty object and i'm going to call this number hi listener we'll reset the transform here i'm going to add like two layers of yeah whatever let's see reset we'll add a game event listener here and i want to listen to the health i'm trying to think what i want to do here i want to bind it i'm going to remove this i'm going to add a binding add a save number binding that doesn't do that though i want it to bind and fire off another event now i'm getting myself all kinds of mixed up on how i want to hook this up because i don't want to do that either so what do i really want to do i don't like this number too high part i'm going to change it out this is what happens to start start writing too much code here so on my listener instead of just making a general listener that listens here let's do one real quick for like i'll enable it when i when i click plus and then i want to write up some better code because i feel like i could dive into an example but it was not going to be a really great usable example so i want to make it a better usable example so let's change this up let's make it so that when the number went up i'll say a number went up and i'm going to change rename this to number went up and then here's what we'll do we'll go to our add button here and then in the on click i'll hit plus and we'll change add the number went up go here hit game event and invoke so now what's gonna happen is when we hit the add button this will fire off this number went up will get invoked everything that's listening to it which includes this little number high enough text will fire off its um event so it'll fire off its unity event and this text will change to number went up and then we'll write um an overriding game event listener and kind of wrap it up from there so it says nothing yet hit subtract nothing changes blah blah blah that's it but why did nothing go to oh i'm in level three sorry hit add and number went up i think this subtract button is not hooked up in level three is why that didn't work but you see that that worked it changed it and it worked and if i change what this listener is doing and change this to like number one up 55 and hit add again it goes to number one up five obviously that's just regular unity stuff all right so let's stop playing i want to add in a overriding game event listener real quick and then um i think i want to do with it after that i think that's about it so let's add in a new game event listener so let's add in a um public class um yeah i don't want to add this part yet i think i'm gonna cut it right there and just um let's just jump over to chat i'm thinking about it and i want to make sure that this is uh that when we get to the the final video that this is kind of perfect so i want to just go through chat see what everybody else has got um for ideas if anybody's got thoughts and i also just wanted to point out that there's a unity stream that's going on in a little while where they're going over the live projects let me pull that up too youtube unity live stream that i think is kicking off in like about a half hour and i think everybody probably go check it out if you haven't seen it yet it's the uh oh it's a different one than i thought okay cool i'm gonna go check this one out too in a little bit so this uh live game jam one and go check that out after this call okay anyway let's jump back in um let's go to chat and see what everybody's saying if anybody's got any any cool ideas or anything um i'm just kind of scrolling up through the chat real quick to catch up because i missed pretty much everything see people like the dark theme i love the dark theme too um what's the difference between an action and a unity event slash unity action good question um so the unity event is the thing that you it gets serialized into the inspector and it's the thing that gives you how to explain it a unity event is well it's a not a c-sharp specific thing it's a unity specific thing that is really meant for allowing designers or programmers or anybody to hook up the connections between the objects in the inspector i mean the the real difference is that a unity event allows you to connect your objects and your callbacks in the inspector where an action or an event like an event action in your c-sharp code is going to be all through code now the difference in where you would want to use an event versus a unity event is really that with a unity event you want that to be stuff that's more content related or gameplay related where your your design changing or the content of your game changing would mean that you would need to change those events or those hookups the way that those things are wired up a regular event like a c-sharp event you want for your more poor level stuff the things that are like at the heart of your game that are like your base systems or the the lower level parts of your systems where things are wired up where you don't want designers to go and change them or if a designer went in and changed it on accident they would break your entire thing all right let's go into um any other questions that we had here scriptable objects for dope sauce yep i agree i think they're pretty cool um oh one question was um about have i heard of people saving data through scriptable objects yes so one thing you can do is save your state of your data you can kind of to json out your data save that out and then you can from json the data back so you can put your data into scriptable objects and kind of save that game state data out and see that data there and then save it off and then reload it you can also just do that with a serialized object it works about the same um just essentially just serializing the object um so it doesn't necessarily need to be a scriptable object personally i think i prefer to have a tiny layer of separation there but it just depends on on the game or the project i think that yeah saving data out through scriptable objects can definitely work um obviously you don't want to save out um you don't want to try to save content in them across like game sessions without pushing it out somewhere you should you need to serialize it out somewhere either locally to a file to player prefs to a cloud save like steems cloud or somebody else's cloud save setup or something like that okay what else we got here um oh somebody said that everybody should hit like i agree if you haven't already hit the thumbs up button i would appreciate that scrolling down through let's see um i have an interview for unity developer position i really want this is the last interview for the entire team apparently it will be around four hours any advice from chat oh um or research it a lot like research the company research um the people the things that they've worked on check to see if there's anything that they've worked on that you're very interested in too sometimes you find that like you're going to work at a game company and the game developers there like one of the people you're interviewing with like was a big part of some game that you were obsessed with when you were a kid or something you never know so i say look into um as much research as you can about what they do who the people are and what they're working on like what kinds of problems they're actively solving especially if they actively blog or write about like what they're working on or kinds of things they're doing and um i just just keep being prepared that way i mean the more you know the more you have to talk about um the better things to go and especially if you can make some personal connection there too so it always helps you know it also kind of relaxes and calms down so you can get to the technical stuff a little bit cooler let's see what else we got here some automated testing on scriptable objects uh we might do that i'm not gonna do that today but i think that would be an interesting one to do um figure out what what the they're usually so lightweight that um it's not so much that you have to test the objects it's more testing the ways that the interactions are working and are hooked up um but there's a i guess in some cases there's a little bit you can test there on the actual objects too uh we're doing a scriptable object be better than having a scene with persistent stuff when would you do one over the other um so using a scriptable object can be better for having um persistent like data that's going across your entire game state um if you want to have but if you need actual objects which you do too then having um a secondary scene it would be good too mike my general recommendation would be to probably have both have a scene that's got your commonly shared stuff that's staying up across scene loads so if you're going into multiple levels you have you know your same camera object or whatever that are they're staying around and management objects and then you can put your staved data um you could save a lot of that into scriptable objects they could then just be referenced from those common things for for their use so you've only got you don't have a reference to them in all of the scenes you have a reference to them in the common scene um and then yeah you still have kind of the same thing but then you can reference them from the other scenes if you need to if you have like some shared flag that like you know level six needs to know about this flag and level two needs to know about this flag also your flag system needs to know about it then all three of those places could all reference it from the project view and not have to worry about it and not have to write any code to wire that up all right um i don't know what's going on a lot of question marks other stuff i don't see anything else um so it looks like we're just about out of questions and i'm about to go do a science experiment with a little toddler so i think i'll wrap it up now and just say thanks to everybody for coming out and if you guys have um i guess just suggestions on other things to add in for scriptable objects i'm going to probably record a video tonight maybe tomorrow on scriptable objects and go through like a well-edited step-by-step like here's how you hook it up here's the thing you do for the the top three four right now i've got three so maybe i'll go up to four if there's a thing um things to do so if anybody's got feedback ideas recommendations um stuff that i said wrong or did wrong right here let me know in the comments so i can um fix it out and uh ammar clark can have a shout out sure cool all right um all right thanks everybody i appreciate it um don't forget to hit the thumbs up button and the like and alert and also don't forget to go check out that uh unity stream that's kicking off i'm gonna go watch that uh while i write code and prep and stuff after i finish up this this experiment all right thanks again everybody bye you
Info
Channel: Jason Weimann
Views: 16,892
Rating: undefined out of 5
Keywords:
Id: oF6LEZQp4jk
Channel Id: undefined
Length: 48min 34sec (2914 seconds)
Published: Sat Feb 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.