Event Bus & Scriptable Object Event Channels | Unity Game Architecture Tutorial

  Рет қаралды 9,724

LlamAcademy

LlamAcademy

Күн бұрын

Пікірлер
@MalikenGD
@MalikenGD 6 ай бұрын
The main issue I see with this approach is the number of scriptable objects you then have to create and fill your project with, one for every single event you could need. You mention when reaching for a static class it's because you want something fast, not scalable, but I look at 100s of potential scriptable object event channels and see that is not scalable. Really surprised you went from an event bus to this, but I get the rationale, just not the solution. Good video, and great way of explaining generics. Never seen it explained that hand-holdy before, and I'm sure it helped someone stuck on the concept
@davidschmitt9210
@davidschmitt9210 6 ай бұрын
Great tutorial! I really liked that you offered both a code-driven approach and an inspector driven approach. The 2017 Unite talk is geared toward studios that have dedicated designers with an emphasis on inspector use. Your guide is very balanced, showing how the inspector setup is an optional step beyond what can already be done in code! Thanks so much 😁
@4rcant
@4rcant 6 ай бұрын
I'm having nightmares trying to make everything "open-close", and this video just scratch that part of my brain. thank you
@halivudestevez2
@halivudestevez2 6 ай бұрын
do not get fooled by SOLID princibles. They are told to be "clean code" tools, but in real life, you just get confused. I don't mean it is completely useless, or harmful, but keep your eyes open, and ask questions if it is useful in you case, or rather makes things complicated.
@zivv1147
@zivv1147 6 ай бұрын
I really like your tutorials. They are of the best ones out there. I want to add a wishlist to your tutorials - that you will make a tutorial about google analytics (Firebase). That is how to to setup custom events with parameters, how to test its working, etc. I've been searching for ages and still haven't found good and up-to-date tutorials about it.
@kantagara
@kantagara 6 ай бұрын
Awesome video. I think the best one I've seen so far in regards to Event Bus being more designer friendly :D
@dreamisover9813
@dreamisover9813 6 ай бұрын
I've been using something similar - just in code without scriptable objects. But it has been really convenient for decoupled logic and avoiding logic from breaking when certain other objects don't exist in the scene
@Sethizback1
@Sethizback1 6 ай бұрын
Thanks! A very helpful example of using static classes. In my project individual units had to be registered with appropriate manager classes on enable and that caused a lot of headache to manage. I will try to move most of this logic into the event bus system you've explained and hopefully adding more particle and sound effects events in the future will be much easier. The TODO list keeps growing, no matter how many refactoring passes I do...
@LlamAcademy
@LlamAcademy 6 ай бұрын
Make sure the refactoring passes are helping you deliver value to your game. Eventually "good enough" has to be good enough and move on 🙂.
@andrewz8763
@andrewz8763 2 ай бұрын
Should the Event bus itself be a singleton implementation instead of just static since static classes aren't guaranteed to be thread safe?
@ishikindofyouknowwhat
@ishikindofyouknowwhat 5 ай бұрын
Very clear video, now, im starting to understand but I still wonder if story driven dialogues should be handled by events too? Like lets say a character which has different dialogue based on game advancement?
@ragerungames
@ragerungames 6 ай бұрын
great tutorial. nice and easy to understand. thanks
@publicmmi
@publicmmi 6 ай бұрын
Like always, a great video! Thanks :)
@LlamAcademy
@LlamAcademy 6 ай бұрын
Glad you liked it 😁
@joaopedromonteiro2517
@joaopedromonteiro2517 6 ай бұрын
In a real world scenario, would you use this buses only in events that connect different systems/unrelated parts of code? I do use a lot o Actions in my code, and many of those are to bind together closely related scripts, like the Player triggering some small events that are used in other scripts of the same hierarchy. In these it seems like it'd be and overkill to create all those classes.
@LlamAcademy
@LlamAcademy 6 ай бұрын
It depends on the complexity of your game. If what you have is working well and scales to the level you need it, you're good! If you find out some of those events need to be listened to by other scripts, you may consider refactoring those to a global event bus with one of these 3 methods.
@raymk
@raymk 5 ай бұрын
My problem with Event Bus is that everything can call everyone at any time. Being able to call any method through an event is super convenient and helpful for designers, however it's easy to lose track of which system should only talk to which system. If everyone can talk to anyone, there's not much incentive to keep the Enemy system only influence the enemies and not any random experience bar.
@halivudestevez2
@halivudestevez2 6 ай бұрын
I'm trying to avoid assigning events in inspectors: these assignments are easy to loose, they also fall apart if you add more parameter to the event. They are also untrackable, and hidden from the code aspects: you cannot track doen, why that event happens. I ban UnityEvent-s from my code as much as possible, and go by System.Event. More stabile.
@halivudestevez2
@halivudestevez2 6 ай бұрын
I have many criticizm about this approach, since I solodev and has negative, real-world experiences...
@LlamAcademy
@LlamAcademy 6 ай бұрын
Yup. If it doesn’t work for you and your workflow, don’t use that approach!
@sadbuttrue666
@sadbuttrue666 6 ай бұрын
@@LlamAcademy Shouldn't it be quite easy to solve the problem with the messaging approach? It would only be necessary to insert a message in the base class, which is given to each event and can be read at a suitable point. I currently use the signal system from DoozyUI and it does exactly that. Each event also has a message payload. There is then the SignalConsole and the StreamsConsole in which all fired events are displayed.
@Briezar
@Briezar 6 ай бұрын
I have the same approach as yours; if there's a Button component that needs to register click events, I'd create a reference to that Button and hookup from code instead. But then I am a programmer, I have the option to do that. It doesn't apply to designers who shouldn't be touching any codes.
@aarndal90
@aarndal90 6 ай бұрын
@@halivudestevez2 I think that's the most important point. I am totally with you. C# events are definitely the better approach to keep a better overview and not lose references. But using Unity events/event management via the Inspector also allows game designers and other disciplines in larger teams to make changes without having to intervene directly in the code, which is something you absolutely want to avoid as a game programmer ^^
@dbweb.creative
@dbweb.creative 6 ай бұрын
Can you please make a video about saving/loading player inventory, where items are ScriptableObjects. I understand that one way to go about it is - items have to be serialized by their guid or by some sort of another id, and then maybe lookup tables or something. This way there needs to be a way to scan and add SO items to lookup table in the first place... Basically I don't know which way to go about handling this whole topic, please ponder this topic in a video, thanks.
@sealsharp
@sealsharp 6 ай бұрын
Here's my "scan for all ScriptableObjects of a type" method. public static List GetAllInstances() where T : ScriptableObject { return AssetDatabase.FindAssets($"t: {typeof(T).Name}").ToList() .Select(AssetDatabase.GUIDToAssetPath) .Select(AssetDatabase.LoadAssetAtPath) .ToList(); }
@dibaterman
@dibaterman 6 ай бұрын
Sadly Godot doesn't have static actions or delegates, in there we use signals which are really convenient in their own right. I had made an event bus and made a event system which all signals emit a object Event which contains a type String and variant data (dynamic data). This isn't too bad but in bigger projects I am thinking this isn't good. So I was thinking of going with exposing the event bus via using Resources (Scriptable Objects) and putting a signal in that. Not sure... Regardless another neat thing is a broker pattern where you can get back the other end of this system, this allows for sending lamda's to handle logic inside of a broker which works independently of the origin or even the thing using the broker. So if I have say Attack and it's 0 at base but I equip a sword with 8 attack, the attack getter simply needs to return broker and whatever identifier the parameter is subscribed with to return 8. This stacks with all modifiers and I can even get a list of all modifiers and their sources since the broker knows all XD. I recall in Unity not enjoying the event channel workflow, it made it feel like drag n drop hell.
@SunSailor
@SunSailor 6 ай бұрын
If working in a bigger team, you must even expect team members, who refuse to touch prefabs, scriptableobjects or such at all.
@SebastianZoellner
@SebastianZoellner 6 ай бұрын
It is not entirely clear to me what the benefit of using a events bus is over using the standard system events.
@LlamAcademy
@LlamAcademy 6 ай бұрын
What do you mean the “standard system events”?
@dunglevan391
@dunglevan391 6 ай бұрын
Are there any differences between Event Bus and Scriptable Object Event Channels ?
@LlamAcademy
@LlamAcademy 6 ай бұрын
Yup that’s discussed in here
@kadircalloglu2848
@kadircalloglu2848 6 ай бұрын
its look like zenject event system
@tufanaydin6340
@tufanaydin6340 6 ай бұрын
Thanks Liaaaaaaam
@halivudestevez2
@halivudestevez2 6 ай бұрын
why SciptableObject for this? I have a MonoBehaviour for eventbus, for LevelEvents.
@LlamAcademy
@LlamAcademy 6 ай бұрын
Why do you need a MonoBehaviour for this? You do not need a GameObject nor the lifecycle methods like start/awake. 🙂 there are many ways to approach a problem. In this video I show a typical standard C# one, and two that Unity themselves have suggested in their e-book.
@RimuruDev
@RimuruDev 6 ай бұрын
Cool
@Daeniak
@Daeniak 6 ай бұрын
Bread
@sealsharp
@sealsharp 6 ай бұрын
🍞
@Daeniak
@Daeniak 6 ай бұрын
@@sealsharp Bread
@franciscooteiza
@franciscooteiza 6 ай бұрын
How old are you? Maybe 30 or 35? You can't have more than 20 years of experience as a programmer.
@halivudestevez2
@halivudestevez2 6 ай бұрын
he worked overnight, too
@LlamAcademy
@LlamAcademy 6 ай бұрын
Well if we take either of those numbers 30-20 = 10. There are plenty of kids programming at 10. 35-20 = 15, people are taking boot camps at that age. I started programming in the late 90s with Visual Basic.
@Fire-Pixel
@Fire-Pixel 6 ай бұрын
FIRST :)))))
@LlamAcademy
@LlamAcademy 6 ай бұрын
😎
@jackblack9872
@jackblack9872 3 ай бұрын
tutorial on how to make your game impossible to remove from the unity game engine. 🤣🤣🤣
@halivudestevez2
@halivudestevez2 6 ай бұрын
you just overcomplicate simple things.
@halivudestevez2
@halivudestevez2 6 ай бұрын
sounds great for the first glance, but in real, it's bullshit. Bus< ??? you have to find out, look thru your 1000 code finding out what to write here. While "Bus.
@EmilM-pb2hn
@EmilM-pb2hn Ай бұрын
@@halivudestevez2 Just say you can't code man. Its kinda evident
Learn to Build an Advanced Event Bus | Unity Architecture
13:27
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
SIMPLE Tip For Better Unity Game Architecture
12:57
git-amend
Рет қаралды 39 М.
The Power of Scriptable Objects as Middle-Men
17:41
samyam
Рет қаралды 132 М.
How to Program in Unity: Observer Pattern Explained
15:57
iHeartGameDev
Рет қаралды 118 М.
Starting Your Unity Game Flawlessly (8 Steps)
9:51
PracticAPI
Рет қаралды 32 М.
The MOST WANTED Unity Feature is FINALLY here!
12:15
Code Monkey
Рет қаралды 56 М.
Improve Your Unity Code with MVC/MVP Architectural Patterns
15:32
ULTIMATE Event System for Unity Beginners
8:27
This is GameDev
Рет қаралды 53 М.
Code Like a Pro: Refactoring to Patterns!
25:52
git-amend
Рет қаралды 10 М.
Events & Delegates in Unity
13:20
Game Dev Beginner
Рет қаралды 65 М.
Top tips for scripting in Unity 2022 LTS | Tutorial
13:43
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН