Scriptable Object Event Systems In Unity 2022

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello YouTube you're looking for as well today my name is Alan and today I want to talk about something that I've talked about quite a lot on the channel scriptable object and events Channel 4 you know I face an event system always going on about how great it is and how much I wanted how much I like using this and and all that kind of stuff but I've never actually shown this or really talked about it in detail so that's what this video is all about we're going to talk about it we're going to get into it yeah so let's jump in so what the heck am I talking about when I say scriptable objects event system well it's based on a GDC talk by a guy called Ryan hipple that I saw many years ago and to break it down it's a game architecture pattern that'll allow you to build all your systems modularly and remove any kind of coupling or or dependencies and how it works with the actual engine's point of view is there's two pieces two components to the puzzle of course there's the actual game event and that is something that is well that's an event that happens and when it happens you raise the event and basically shout outs until your project that this event has happened then you have a bunch of listeners and they are listening for a specific event and they're all going to do an action based on that event and I'm about to show you a bunch of examples of this in my own project this is a scene I just finished for the iso pack that I'm making and this is basically just showing off um our RPG systems for so level XP and attribute scaling built spoiler by the way because there's a tutorial coming up uh on this very soon or the teaser so if you liked it look at this subscribe huh subscribe uh and a little demo if I have a level up button when I press up this increases and uh my character stats scale up as well and this is all done using an event system and this is a great little example of how Event Systems are good So within our canvas we have the stats container and we have all of these different stats so these are just texts um just containers that contain some text values um that we play with it's not that important but what is important is that how you would normally do this for yourself and without an event system is that you would need to create some kind of script that you would maybe pass all of these values into it and have them all as public variables within the file or you would maybe just pass the entire container in and you would get all the children for all the children were in the container and you just kind of have to assume that it only has stats containers which is fine I mean it works right it's fine um but with an event system is that there's absolutely no connection between any of these uh objects or any other class everything is completely selfish right so uh what is happening in this scene is inner level changes we have the level up and then like I said about the the game object so we have a level change game event and it calls something called a raise method which is basically just it's basically shouting out into the walls that it's it's done its job it's finished and it's it's uh something has happened and then in all of these stats containers you know held we have the game event listener and it's listening for that event and it's doing something when it hits that event so in this situation it's just updating the text which isn't it's not not a big what what a turn isn't that important we can you can wait for the tutorial on that um but it means that all of these things are just completely separate and I don't have to change anything and nothing has any dependency on each other so I could just easily just duplicate this uh this this one I could go into this I could it's set to intelligence right now let's set it to help again I'll press play it's automatic change the health and it's scaling up automatically just nothing I had to do there's no no um dependency I didn't have to you know drag this in anywhere or anything like that so it was just really good and the reason I'm not doing a full tutorial on this it's showing off the code for the game event is because it's really just copied straight from that GDC talk that I was talking about earlier so it's kind of plagiarized so that's why I don't really feel comfortable doing a tutorial I don't think it's necessary if you want to copy this watch that talk I highly recommend it it's great talk and just even see if it's something that you want to do so so if you want to do this and there's other tutorials out there as well so you don't you don't need me um to get this done I don't like and uh that's not all this scene here is from the AI video that I did just a little while back and this is an example of just a much more kind of complex scene and kind of what events do here so uh within this scene there is one particular event that is kind of prevalent everywhere so and that is the focus character event so uh basically what the focus character event is is when a new tone begins we get the next character on the list and who's next and we raise an event and we tell basically all of the different systems who the new character is and those systems for example are Pathfinder controller uh we have the torn based we have the character event manager and we have the time based manager we also have the canvas UI uh to update the little image down here and yeah probably a couple of other things that I'm forgetting about but it's it's everywhere this event is everywhere and what's cool is that all these systems none of these systems are reliant on each other or aligned on a character existing or anything like that so for example like if I press play here uh you know everything is working fine right if I go to my portrait and just say you know what I don't want a UI I want to disable UI no I can just disable it and everything still works completely fine as expected and that's really cool I think I think that's really cool yeah I don't know have I booked mines break my buttons but yeah that book um I must have deleted the image by accident when I started a new project anyway uh yeah the only downside in my opinion to these Event Systems is organization organization is kind of tricky and this project is a great example of how maybe it's things can get out of hand because what I did was I just um what kind of events everywhere and I didn't really care where they went and listeners everywhere so like discount or event manager has like sex different other types to it probably not necessary I think what I'm gonna try to do for the new project is have like listener objects that just kind of just holds all the listeners in place so if I need to find where they are I can and it's not a big deal for example like I'd have one Focus character listener and then I would have like my pathfinder controller then I'd have my event manager my torn based manager and my portrait right and then I would call whatever functions it is that they need to call I'm not gonna I'm not going to do that the offset waste your time by setting it up here but that's maybe something like this is probably better than um what I've done so that's just kind of something to keep in mind and another downside is that sometimes you can end up with these kind of chain and event chain of events and if something goes wrong it's kind of hard to figure out what goes wrong it's hard to go backwards so uh for example um the focus character event raises and if I go to my character event manager this is one of the methods that gets called from event and let's just say like this character that's getting passed to it uh some bad data inside of us right how would I figure out where that bad data is coming from if I haven't walked on this project in a couple of weeks or a couple of months right normally if a med it's been called from somewhere you can just click on this references button here and it'll tell you where it's been called from you know if I scroll up for example like it would look something like this uh oh you know I could right click on it I go to find all go to implement I'll go find all references um and my references are just I'll just there is none right uh or I could maybe I could like click on it I could do like a control shift f and we could find all that which is that way but no there's just a bunch of methods with the same name there's nothing being called so something to keep in mind um it can be kind of tricky so uh good naming conventions good good naming conventions and uh hierarchy good hierarchy organization is very important for these systems and I haven't done it here with my first time doing it and the scene got a little bit over complicated but going forward is definitely something that I want to keep in mind and trying to keep everything as clean as possible uh but yeah that's kind of the end of the demo and that's it that's everything I wanted to talk about today uh I know this was pretty low effort but yeah I hope some people found it interesting or useful in some way I'm trying to find a balance where I can upload more videos but not lose too much quality so I'm trying to like figure it out and I'm just kind of playing around with ideas and trying to figure things out so so give me some feedback down below um if this was any good or if you found it interesting at all and the only other thing I wanted to say was 1 000 subscribers we did this uh thanks so much guys I I kind of gave myself a little uh a little like mini goal in my head to say like I wanted to try and hit 1000 subscribers this year and you know we'll have to treat you and it's there so I'm just like really happy about that and yeah I feel really good about it so yeah thank you thank you so much um that's all I wanted to say uh see you next time next there is a tutorial coming I'm on the apogee systems so if you're interested in that and keep an eye out uh yeah cheers thank you bye see you soon foreign [Music]
Info
Channel: Lawless Games
Views: 6,937
Rating: undefined out of 5
Keywords: devlog, game development, indie game, unity, game dev, gamedev, indie game devlog, indie dev, dev log, indie devlog, indie game dev, game devlog, indie gamedev, coding, unity game dev, indie devblog, tactics devlog, game design, indie, gaming, indiedev, pc, playstation, indie games, programming, tactical rpg, srpg, isometric, isometric map, isometric games, unity tilemap, unity isometric tilemap, scriptable objects, unity scriptable objects, character systems, rpg characters
Id: uXKX5O8wiac
Channel Id: undefined
Length: 11min 13sec (673 seconds)
Published: Mon Jul 11 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.