This is great stuff Jason. Your specific tutorials such as this one always help me out a lot. Your channel is great!
@peterhou77173 жыл бұрын
Very interesting. I work with designers a lot, but never thought of exposing events to them like this. Thanks for sharing.
@Choco-sk2gj Жыл бұрын
Jason, i just wanted to report back and say I used game events/Scriptable objects for the first time today after watching your vids, and also I read the article you mentioned and wow, very powerful stuff! I'm glad it totally clicked with me because the biggest thing that always seems to be holding me back when i tried any game engine, is getting all the parts to communicate properly without errors or bugs, to the point where it actually overwhelmed me more than anything.. and finally i feel i've found a way to build my games that really suits me and won't have me pulling my hair out thanks to your videos! I just got up and legit cheered when I just had an event easily do everything i wanted it to do, felt so good! Multiple features in my game just got added within 20 minutes because the only solution i needed was a way for the parts to communicate as some were not. That article is fantastic too the way it breaks down the sword data and what not, thats a great example to refer to. I think a lot of people are like me where even though they may be somewhat new to programming/Unity, they can actually code stuff they need to make or always find a way but they just suffer with the fundamentals like how to get parts of the game to communicate easily without running into walls, more people need to see these videos and be aware of Scriptable Objects and Events and how they can tie together. I feel more free now to make my game.
@victoraurelius53343 жыл бұрын
'ScriptableObject-Architecture' - free Asset on Unity store implementing all this for you. There is only one major flaw with this pattern, which is never talked about. I learned the hard way, after implementing this in my project. That is, that you lose any reference-tracking with implementing this ScriptableObject event (or any other type) system. What do I mean with that? If you take a look again into your IDE (Visual Studio), you will notice that there is no helper for WHICH class is calling/using this ScriptableObject. It is a interface into the void. You are fine with 1-5 ScriptableObjects like that. But in a more bigger project, you will effectively have 100's of those, to manage your game mechanics. And will suddenly wake up in a nightmare. "Can I safely delete or modify this SO, is anything still using it?", "which systems are actually using this SO?" those will be your main concerns each day. I found it to be very frustrating and removed the system completely at the end. Just a heads up.
@ivandamyanov3 жыл бұрын
I have a playlist with game dev tutorials for when I get deeper into a project and i bump into problems / want to improve performance and so far your channel totally dominates said playlist. Literally the best programming channel for game makers! Sincerely thank you man.
@saqibbro52972 жыл бұрын
Wanna share the Playlist :) Plz
@szaaary3 жыл бұрын
I didn't appreciate the events until I had to turn my 3d game into d2. Swapping scenes, collisions etc. I was downright shocked at how easy it was for me. Most of the logic was based on them. And this is just lvl 2 of this :D It's great.
@UnfamiliarLandsGame Жыл бұрын
Thank you for this video. It really simplifies triggering actions between scripts a ton.
@fernandoz63293 жыл бұрын
Clever Code. It takes little effort to understand and it takes you to another level. Awesome.
@sqwert6543 жыл бұрын
Brilliant having moved back to Unity from UE recently. This technique will keep me working my core game mechanics rather than working on say dissolve mesh effects before the core game is done :)
@iDerp693 жыл бұрын
I use a similar pattern with C# Action delegates for blistering fast performance and ease of communicating across scripts in my project.
@Ryan-ww7un3 жыл бұрын
Incredible timing! I started learning about the observer pattern and C# delegates yesterday!
@leohunter53602 жыл бұрын
Appreciate the fact that you explained every little thing that you were doing. Good job!
@matounette66673 жыл бұрын
Really interesting. I like how well it is explained and is not only for advanced users (explaining quickly each concept). Thanks!
@Asylum3D3 жыл бұрын
This is cool. Another chunk tip/trick to throw in my bag of goodies! Thanks for all of these videos. It makes a big difference for us.
@yellowmarschmallow41023 жыл бұрын
Agree 100%! I've built my game using Scriptable Objects with events extensively and it saves you so many headaches! Everything is much better separated and can still tightly work together.
@ViciousProgressor3 жыл бұрын
This is a great technique; thank you for sharing it! I appreciate the way you frame explanations of a system with potential use cases and intent. It makes things very clear and straightforward.
@geri43673 жыл бұрын
OG Jason is back!!! Love this kind of content
@joliveres3 жыл бұрын
0:23 Getting fancy with the editing there!
3 жыл бұрын
You make a huge difference in my life as a developer. When I finish some games and start making money with it I'll definitely become a Patreon. Thanks for the videos!
@drakorez3 жыл бұрын
This is very helpful. thank you. I am new to Unity (came from UE4) and I did not even know that there was a "Unity Event" variable I could use like that. I will be using that in my game for sure.
@hugogogo13 Жыл бұрын
Awesome video and awesome trick for decoupling relationships. Thank you 🙏
@JoshLmoa3 жыл бұрын
Thanks a lot for all your videos. I'm in a 2 week isolation and binging the hell out of your content to fill by goopy brain with knowledge.
@MegaBoxer13143 жыл бұрын
This is a really useful system. I first seen it used from a Unite talk on scriptable objects.
@MarkRiverbank3 жыл бұрын
I use UnityEvents or standard C# events frequently. It took me a moment to understand what you’re doing here moved the editor configuration to the listening object rather than the sender, which makes a lot of sense from the design side.
@rorychockman10523 жыл бұрын
I like editing in this video, all you need is sound effects and your done!
@erickmarin2282 жыл бұрын
This is a great way to implement the observer pattern. Thanks for sharing !
@yusufalibrahim19943 жыл бұрын
Hey Jason, your videos are awesome. Using dark mode will make our eyes healthier!
@sytix13 жыл бұрын
Cool. I don't see how I can apply to my game now, but I've learned more about the SO and the UnityEvents.
@DePistolero3 жыл бұрын
Hey, thanks for the hashset tip, will change that, I actually use the same workflow for my game architecture, it is insanely modular, quick to develop and a bit of a pain to debug sometimes, I just recently put all the events in a singleton class, so they can be easily invoked from any script, and a bit easier to find references and debug, and you avoid extra work for classes that have to invoke event, no inspector references( granted, that has drawbacks, if changing scenes, but is easily worked around ) Also naming convention must be respected here, when it comes to events and methods that are calling them. As an extra, I made the editor script dropdown that lets you choose what type of an event you want the newly created event to be( empty, vector3, int... whatever, it just lists game event methods ) So each listener, will display only calls that assigned event has. Also added to this is a default event to call, just an empty event, in case of gamesuccess, and gamefailed, there is an default event game completed, that always triggers in both cases. very useful. Delay is the same with coroutine, but each event call method has a condition if delay is > 0 start coroutine and fire the event after the delay, don't have delayed event and regular. Drawbacks to all this, bit harder debugging, a lot of references in inspector, but if you put on each event listeners list, it also becomes a bit easier. Pros: insane modularity, flexibility, development speed, and development agility, keeping things very orthogonal. that GDC was mindblowing, I am also using all the time those reference fields, that accept either scriptable object value, or just regular value, pure gold this all is. I wouldn't want to develop in any other way honestly... Thanks for the tutorial.
3 жыл бұрын
Man I love your videos. Thanks for existing
@6bytes3 жыл бұрын
Good timing! I had this exact problem moments before this video was uploaded : )
@gadgetboyplaysmc3 жыл бұрын
This is amazing. Definitely upload more amazing programming practices
@MatthewAWinston3 жыл бұрын
More excellence! Thank you!
@alextreme982 жыл бұрын
Big thanks for this implementation. I was curious about the event scriptable object to use it as an architecture for the game 😁
@Atezian3 жыл бұрын
Holy smokes this is going to make everything much quicker. Thanks Jason.
@DustVoltrage3 жыл бұрын
Looks great, thank you Jason !
@Senkh3 жыл бұрын
Really looking forward to the other things you will suggest doing with scriptable objects :)
@averydee53282 жыл бұрын
Thank you so much, my code is so much more flexible now. God bless.
@albertolameira52243 жыл бұрын
awesome video once again :)
@leandro_damasceno3 жыл бұрын
Thanks for the lesson, Jason!
@buffalobuffalogaming3 жыл бұрын
You have saved me from tons of problems. Thanks!!
@goldone013 жыл бұрын
This is awesome - thanks for the great video!
@dominikpotulski5763 жыл бұрын
Hey, super video. I actually already implemented this system into my game but I have problem when it comes to connecting other systems and monobehaviours together. As a solo developer I can't really tell where the line between design and programming is. What I mean is that I don't know what to connect through code and what to connect via an event system. Because I code since 9 years and I got into game development only last year, my immediate intention is to hook everything up through code but this obviously leads to said problems and I would need to do a rewrite every time I would like something to get changed. On the other hand, if I connect all those system together with an event system, it's not written down, can be forgotten, etc., like the other Jason said in the last game dev talk of yours. It would be incredibly helpful if you could make a followup video where you name some guidelines and tell us about your experiences with connecting systems. I think many solo devs and small teams would learn a lot about how to structure their game robustly while keeping the needed work low to change and / or add something new to their project.
3 жыл бұрын
IMO the line should be where it affects your business logic. Anything affecting business logic should be in code so that you can track it through your IDE, git and verify in unit tests. If it only affects a view (spawn particles, show texts or effects) then you could use the method shown here. That is if you're a professional who wants to build scalable systems of course. If you're just experimenting, learning and having fun then this can be a quick way to iterate.
@jovarus3 жыл бұрын
Seems like a great tool for updating my ui panels on certain events like updating currency display.
@Ferenc-Racz3 жыл бұрын
Thank you very much. Your videos always useful and there is always to learn.
@Chronomatrix3 жыл бұрын
Game programming is truly overwhelming, I'm currently trying to learn patterns like factories, observers, commands, adapters, etc. and there's always something new popping up. Just learned about abstract classes and invokes and now here comes game events, and I know it's just the beginning! Does it ever end? I find most of this stuff really hard to learn without real examples of how to implement them, and it gets even harder when you try it yourself on more complex features. All this knowledge is insanely fragmented into hundreds of courses, books and youtube tutorials. How do most people learn about all of this?
@franciscokloganb3 жыл бұрын
None of the mentioned concepts are particular to game development; Most of the concepts you mentioned are just typicall programming things you learn as you go. The more you program the more you learn, but eventually you get to a point where you must accept you can not know it all. It is often more important to know a certain tool exists and use it when it is needed. :)
@MohanABK3 жыл бұрын
I'm glad you think this way. This is the life of a programmer. And you're just talking about game development; it's even grander of a field when you want to study overall programming for all things. This is why this field is popular and lucrative. It's large and there's a lot of skills and things to learn.
@thejamesgreensill3 жыл бұрын
It gets alot easier with practice. (as does anything). Sometimes it can take minutes to understand something and sometimes it can take weeks to fully understand how to implment a complex system, algorithm or pattern. But as you grow as a programmer it will become easier, also don't stress about memorizing things you can just google and make sure you use your resources avaliable to you in order to learn.
@Rhysman302 жыл бұрын
Years of practice, broski! I've been at game programming (modding) since i was a teenager, unity for the last 4. Every day I learn something new. You're actively looking for best practices though, so you're already 10 years ahead of me. Keep at it, it gets easier.
@callmedeno2 жыл бұрын
You don't need all that design patterns bullshit, especially when you're building games that you don't even know how they will work or will even be fun, especially prototypes. At most I'd say the observer pattern is all you need to know just to understand events, one afternoon to get acquainted with it and yer done. Write the program
@EnderElohim2 жыл бұрын
Saying no is easier option and work perfectly fine XD
@Dover83 жыл бұрын
I approve of the tutorial reference :]
@asafbenjaminov26353 жыл бұрын
Great video thank you very much! Id like to ask what happens when you need to pass some parameters for the unity event?
@thewolfman44533 жыл бұрын
Thank you! Can you make tutorial about sending through this game events parameters to listeners?
@icon83913 жыл бұрын
Thanks for the tutorial
@Unity3dCollege3 жыл бұрын
Thanks for the comment! :)
@Skdbszksixh3 жыл бұрын
Thanks for the video ^^
@anommymousse12243 жыл бұрын
My heavily interconnected character selection screen with unlocks using some questionable parenting of objects thanks you in advance. Time to refactor and unlink that rats nest!
@joepace18263 жыл бұрын
Would you consider making a series where you play a game (finished or not) find bugs and go through how you would fix them?
@fo43573 жыл бұрын
That would be super useful!
@11sveden123 жыл бұрын
Haven't seen the whole thing myself but I think some of this might be done in his Code Review videos. There's at least 3 of them, possibly more. I would check those out.
@MaximumSpice3 жыл бұрын
Very clever, love it
@mikogronroos40503 жыл бұрын
how would you go about adding different parameters?
@matthewrye31563 жыл бұрын
Yeah, like in this example telling the listeners which enemy died.
@willpetillo11893 жыл бұрын
I have some examples here: github.com/Will9371/Character-Template/tree/master/Assets/Playcraft/Quality%20of%20Life/UnityEvent%20Helpers/Observer
@avinnaidu20222 жыл бұрын
Thanks for the video! BTW, @Jason Weimann - might be really random but what are those tile lights you are using? >
@Games-ew9sp3 жыл бұрын
awesome stuff thanks
@lcd110012 жыл бұрын
(14:19) we can use base.RaiseEvent() inside the override method, right? and the variable _unityEvent still in private
@michelcastilho6862 Жыл бұрын
In the EvenListener I've changed UnityEvent to UnityEvent and I pass a string on Invoke, so I can use it on whatever function UnityEvent calls. In the editor, when I add my desired function to the UnityEvent list on the Event Listener element, I can see that it shows as Unity Event (string) and the string field is available, but it doesn't receive the value I passed on Invoke and the function throws an error because the string is empty, even though it was correctly passed on Invoke. Help?
@sadiqabbaszade47893 жыл бұрын
What about sending data when we invoke events? As far I as remember unity events with generic types can not be serialized (may be they changed in 2020 idk)
@zionen013 жыл бұрын
It's definitely do-able. My implementation has a base class : public class GameEvent : ScriptableObject { //same as game event but with T } Then you would have (int example) : public class GameEventInt : GameEvent { /* EMPTY */ } This becomes more powerful when you don't use primitive types and instead use complex types, especially a base class and inheritance to add data. UnityEvents support one argument so that works nicely, you can drag the GameEventInt to a UnityEvent that has an int argument for example. Works fine. Challenge comes when you want one event to call specific listeners based on the gameObject to support one event for multiple prefab instances, this is also do-able and goes something like this: public class GameEvent : ScriptableObject where T: FSMData { private readonly Dictionary _actions = new Dictionary(); ... }
@sadiqabbaszade47893 жыл бұрын
@@zionen01 wow thats actually a piece of code in the reply lol. Thanks. Yeah I figured out I can just pass eventargs class as a parameter (wrapper class to serialize unity events but thats fine). But instead of creating new classes for every other event args type, I will simply either put them into one class, or use inheritance and downcast the data in listener. Hope it makes sense.
@ulissesnascim3 жыл бұрын
Can you do one with parameters?? I've solved that myself but would love to see your approach.
@nixellion3 жыл бұрын
Could you share how you solved it, please?
@ulissesnascim3 жыл бұрын
@@nixellion sure. I created a SetParameters(List parameters) method in the gameEvent. The method updates a local list of parameters in the gameEvent and holds it until the next Invoke. This means that extended gameEventListeners will be able to read that updated list and do stuff with its information if the correct variable types were passed. So a GameEventListener_FloatParameter would be able to read a float from the list and supply the underlying methods with the float. There are some clear disadvantages, but I've been able to do a lot with this so far.
@nixellion3 жыл бұрын
@@ulissesnascim Thanks! Thought it should be something like that. Will be incredibly useful!
@tofusoup999 Жыл бұрын
This is very helpful.If I need the same event to accept different parameters, what should I do?
@ИбрагимИванов-э3р3 жыл бұрын
Nice trick. I do not like to use events, but maybe I try it one day.
@Drastonar3 жыл бұрын
I've been using game events for a while now, never thought of making a delayed listener, I used to code a monobehaviour that would do my action with delay and call this function on the listener
@matthewrye31563 жыл бұрын
Your way actually sounds more modular and flexible.
@TheMuckGames3 жыл бұрын
Nice video! I tried something like this before. But at some point, I lost the overview, which events fired/registered from which objects. Did you have a solution for it?
@LeFede Жыл бұрын
Why would you use Hashmaps instead of UnityAction ?
@_ian_2 жыл бұрын
Thank you Jason, I like this and use these a fair bit, they are very handy when you want to step back a bit from the code and think like a designer. But is there a way to inject the event name into the title bar of the component (in the Unity Inspector)? that way when I have many collapsed components listening to different game events, they'd be easy to tell apart. Currently I just see "Game Event Listener" for each of them. Thanks!
@pixelpat7773 жыл бұрын
@Jason Weimann Great video, The OnMouseDown() is not working for me, i have it on my player character and i have a 2D capsule collider.
@eqapo Жыл бұрын
How would you extend this to pass data through the .Raise(eventArgs) ?
@callmedeno2 жыл бұрын
hmm I'm wondering, is there any way to modify this so that you can pass data with the event or is it really only for events without parameters?
@Unity3dCollege2 жыл бұрын
Definitely! Ryan h talk.on it shows that really well. May make a followup to this showing how as well
@motifgaming20803 жыл бұрын
The only issue with this is whenever the referenced script is removed or moved from the Gameobject. The Unity event loses the reference and will just show an empty slot. If we take the same example as in the video, if someone decides to recreate the text object by deleting it for some reason. It gets hard in the bigger project to realize what the Unity event was holding the reference of.
@FyresGames2 жыл бұрын
Oh wow. That's great. How do you set up multiples scenes in the hierarchy like this? Look great to disable in one click the whole UI to work on the scene.
@heckensteiner47132 жыл бұрын
I love the beginning of your videos when you're explaining the concepts, but the second you open the text editor with the code I'm like 😵💫. Guess that's why I'm an artist and I'll never be able to program. It's like hieroglyphics to me.
@kmud77503 жыл бұрын
Awesome video! I love using this! How do you approach finding all the references in code when you run into trouble?
@BenVanTreese3 жыл бұрын
If you just mean finding the game event listener objects in scenes, you can search the hierarchy with a monobehaviour name and it will filter to the objects with the named behavior attached.
@Whaiitran31063 жыл бұрын
hey Jason, by the way... what is the font you are using in your editor?
@sergeistarovoitov76636 ай бұрын
I have an issue in a build with that approach. Garbage collector cleans a HashSet in SO during loading a scene: Registering listener: PlayerPopupsUI to event: AnimationFinished_IntroScene; Total listeners: 3 Registering listener: SceneManager to event: AnimationFinished_IntroScene; Total listeners: 4 Unloading 1575 unused Assets to reduce memory usage. Loaded Objects now: 37889. Total: 17.566200 ms (FindLiveObjects: 1.458500 ms CreateObjectMapping: 0.920200 ms MarkObjects: 12.912100 ms DeleteObjects: 2.275000 ms) Registering listener: SALSA_Player to event: AnimationFinished_IntroScene; Total listeners: 1 Invoking event: AnimationFinished_IntroScene on listener: SALSA_Player So only instantiated objects work correctly. In the editor, there is no such issue
@JayadevHaddadi3 жыл бұрын
Question: In the GameEventListener class you have one SerializedField called _unityEvent that is just a UnityEvent, but in the inspector it looks like it is a list/array of events. Is that just how events are, that they can always be added as many instead of just one? Thanks Jason👍😊
@wisher772 жыл бұрын
You can give a UnityEvent multiple things to do when it's called. So yes they are always like that
@JayadevHaddadi2 жыл бұрын
@@wisher77 Thanks Wisher for your patience and willingness to answer my newbie question :))
@lambjalfrezi3 жыл бұрын
What would be a good way of extending this to allow the Invoke method to take arguments?
@mlanc77753 жыл бұрын
Why is it every video I watch about events.. it's totally different? What's the difference between this and using a monobehavior EventManager that uses public event Action onAction? Seems like people have so many different ways of using some Event System and they are all different.. unless using the UnityEvents system.
@goehlergamedev3 жыл бұрын
Do you use this instead of regular C# event Actions?
@mirtzata2 жыл бұрын
Can you implement the similar concept but with actions that can pass int,string,bool?
@songhaoli3043 жыл бұрын
If we consider this method as a decentralized event system. How does it compare to a centralized one. For example, a central event system class owning all the events.
@saltyman56033 жыл бұрын
Genuine question: Why would I want to use this method instead of just programming a singleton and casting to a specific function on it? It does the same thing and uses 1 less script.
@MrSmoofist3 жыл бұрын
Works like a charm! But I want to challenge this system: what if I'm making a card game, and use this to make sure each card has its own unique event when dropping on the enemy. How do I make it pick the right game event each time and the right effect to call as well?
@containedhurricane3 жыл бұрын
What about the memory garbage generated by Unity Events in the architecture?
@kiririn39m83 жыл бұрын
Now, how about creating swappable Sprites themes/Text/Colors etc. On Start it starts listening for a sprite with specific id/guid/alias etc from a data cache(scriptable object). And when some one(a button for instance) wants to change color palete or sprite theme it gives a new set of data(sprites or something) to this cache, cache updates existing aliases with new data set and invokes update on listeners. Thats it. Imagine complex UI or localized text acros different scenes that can be updated by a single button click without explicit references to monobehaviours or prefabs(it can be found by cache itself or use reference to singleton cache)! In simple words: Cache is observer, SpriteChanger is listener, and player clicked button is actual event invoker
@willygamedev81443 жыл бұрын
Is it an implementation of the observer pattern?
@Atezian3 жыл бұрын
how would you pass a float from the object raising an event to the object receiving the event?
@winxalex16 ай бұрын
Creating manual events only if needed and most of the time use modified Unity Event editor. Instead of creating tons of Scriptable objects per event, create Scripable object per topic with list of events. Then refrence where you need it. Main problem with events after time you forget where they are and hard to test if you dont' have something visually like this kzbin.info/www/bejne/m5DcmICMe81-jdU
@abo14283 жыл бұрын
Habe you changed something with your camera setup? Looks much better! 👌🏻
@StevenBloomfield3 жыл бұрын
What's on your hoodie?
@zipzorp88583 жыл бұрын
I am confused. He describes this Game Event as something that doesn't need to be referenced, yet he references it anyway (6:52). I'm confused by most of this. I think I understand the general idea, but the explanation of the scripts is bonkers over my head.
@soma782 жыл бұрын
Anyone else getting this error in the GameEvent.cs script ? "The type or namespace name 'GameEventListener' could not be found (are you missing a using directive or an assembly reference?)"
@dewaldbotha63902 жыл бұрын
Im having that same problem.
@dewaldbotha63902 жыл бұрын
Seems we should finish watching then do the code 🤣🤣🤣
@soma782 жыл бұрын
@@dewaldbotha6390 haha, fair enough !
@pmoneyish6869 Жыл бұрын
It would be nice if registered methods to the game events could be IEnumerable and fire them off as coroutines.
@sellverful3 жыл бұрын
2:55 video really starts here
@disobedientdolphin2 жыл бұрын
Would have been nice to just add a link to that tutorial in the description
@OutBreaker135793 жыл бұрын
wouldn't it be better to use an interface for the advanced usages instead of deriving from the base class?
@royalcrownpro67773 жыл бұрын
It's just a roundabout way to end up doing the same thing. You still have to add the features they want.
@KBforJesusChrist2 жыл бұрын
I'm a beginner and I'm trying to understand how shop system work I haven't found a good tutorial on it, please explain to me how shop system work like u but skins or items and it appears in game how do I integrate it in any game explain they key codes for shop system how it changes game objects please