Using Scriptable Objects for Events in Unity | Scene Independent Event System

  Рет қаралды 16,497

Dan Pos

Dan Pos

Күн бұрын

Пікірлер: 33
@DanPos
@DanPos 3 жыл бұрын
⏰ UNITY BLACK FRIDAY SALE ENDS DECEMBER 4th! ⚡ LIGHTNING DEALS SEE 90% OFF SELECT PRODUCTS Take 50% off the best selling assets on the Unity asset store in their Black Friday sale, now on! prf.hn/click/camref:1101lkANY/creativeref:1011l65259
@VoonNBuddies
@VoonNBuddies 3 жыл бұрын
One small suggestions: Rather than making new classes for each data type, you could create an abstract class that takes in a generic type. This way you can design the general Channel api once without every having to rewrite the functionality. Now, when you want to make, say, a RIgidBody Event Channel, you could simply create a class that derives from the abstract class with RigidBody passed as the generic. Now if you want to change the functionality of your channels, you can do so in the abstract class and any derived classes will inherit that changed behavior. Great video!
@DanPos
@DanPos 3 жыл бұрын
That's a good idea! I'll try and refactor it to take this into account :)
@VoonNBuddies
@VoonNBuddies 3 жыл бұрын
@@DanPos Thanks! I hope that ends up being helpful!
@TheKr0ckeR
@TheKr0ckeR 2 жыл бұрын
@@VoonNBuddies Can you give more detailed information about implementing generic classes in actions for not creating extra classes for extra data typeS? :)
@TheKr0ckeR
@TheKr0ckeR 2 жыл бұрын
I got it. :)
@Legionope
@Legionope 9 ай бұрын
Can you please show us roughly how you'd do that? Wouldn't that be something like OnEventRaised?.Invoke(); ?
@mcinerc
@mcinerc Жыл бұрын
Awesome video, thanks. I retooled it for my own purposes slightly -- I made a single EventChannel script and created an Arguments class that I can basically add any data I want to. Then every event just uses this one event type, and every channel can support any amount of data. It's probably not the most efficient, but it works for a smaller game where performance isn't super important. The core concept is great and helped me start a pretty huge refactor. Much appreciated.
@juliavalerialopez3212
@juliavalerialopez3212 2 жыл бұрын
This is a really great tutorial, thanks for the great example and explanation 👏👏
@DanPos
@DanPos 2 жыл бұрын
Thank you! Glad you enjoyed it 😊
@dotomomo
@dotomomo Жыл бұрын
Great tutorial, completely understood the concept after watching!
@ernestj8000
@ernestj8000 2 жыл бұрын
Excellent tutorial and demonstration of ScriptableObjects and Unity events!
@DanPos
@DanPos 2 жыл бұрын
Thank you! Glad you liked it :)
@alextreme98
@alextreme98 Жыл бұрын
Exactly what I needed to know, all the respect man to you
@takingpictures4536
@takingpictures4536 Жыл бұрын
please fix your mic input. The repeating high frequency audio really hurts while listening.
@FrogKin9
@FrogKin9 5 ай бұрын
That‘s a great tutorial. But I‘m left with a question. In my case I have multiple scriptable objects from the same SO-Script (different Items in my case). How could I check which Item invoke the event? Passing the name as a string with the event doesn‘t feel right.
@klauspeters8078
@klauspeters8078 7 ай бұрын
Hi Dan, do you know how to use coroutine within the listener function? thanks
@looty20-q8q
@looty20-q8q Жыл бұрын
Is it just me, or is there a high pitched beep in the background?
@erosallica
@erosallica Жыл бұрын
Great video! thank you so much. It has helped me a lot!
@GiantsOnTheHorizon
@GiantsOnTheHorizon 2 жыл бұрын
Thanks for a great video!!
@DanPos
@DanPos 2 жыл бұрын
Glad you liked it!
@FyresGames
@FyresGames Жыл бұрын
My middleman singleton for events is gone thanks to you! I just wonder why you use UnityAction instead of Action? Both work the same but Action can take more args if needed.
@Strategiusz
@Strategiusz Жыл бұрын
Does it work in a built game too?
@TheKr0ckeR
@TheKr0ckeR 2 жыл бұрын
I really liked the idea! But what happens if we have for example Trader NPC's and all would have their own "OnTradeCompleted" scriptable object? I found myself overkilling, assigning it different SO events for every trader. If i use same SO, when one completed, others are also affected.
@obikwelukyrian6848
@obikwelukyrian6848 2 жыл бұрын
You could have an OnTradeCompleted event that takes one argument, the Trader NPC class. When each receives the event, it checks if the Trader NPC passed is itself and if so, performs the action
@Justin-qr9mh
@Justin-qr9mh 3 жыл бұрын
Really cool video. Does a system like this work for more Complicated systems such as camera shaking or ui management?
@DanPos
@DanPos 3 жыл бұрын
Yes, absolutely! Here's a great video that uses similar concepts to create an Inventory System: kzbin.info/www/bejne/inOYhHaHZpmdgtk
@qasimahamad5075
@qasimahamad5075 3 жыл бұрын
great one
@iDerp69
@iDerp69 3 жыл бұрын
I usually just use a static Events class with a bunch of C# action delegates, then there's no need to wire anything up in the inspector -- plus I can use Visual Studio to find all references to see what's subscribed and what's invoking. I don't like the scriptable object approach that's been evangelized by the likes of Ryan Hipple (I tried it in my own project and it felt like a scalability nightmare).
@AM-vr4qy
@AM-vr4qy 3 жыл бұрын
I agree. Ryna Hipples systems was a boilerplate nightmare to set up and maintain.
@DanPos
@DanPos 3 жыл бұрын
Definitely another great solution, my main goal with this video was to provide an alternative solution to the Singleton way of doing things but you're right a static Events class which also people a good option and achieve similar results to this, without the need for hooking things up in the inspector. That's the great thing about coding - lots of different ways of doing stuff and its whatever works for you and your project. For example, this implementation could work well if you're working with designers who need to hook things up in the inspector and not look at code.
@windwalkerrangerdm
@windwalkerrangerdm Жыл бұрын
Exactly my thoughts. The hard part is not isolating objects from each other, it's to connect them dynamically, without using the editor to hook things up. In a real case scenario you often need to establish listeners and raisers dynamically, and this becomes an issue even when they are not referring to each other directly. A static Event manager system becomes much easier to manage, you just create a SINGLE reference relationship on ONE end of the raiser-listener system (usuall on the listener side). But what I wonder is, which one is better amongst the following two: (1) all your listeners susbcribe to the EventManager system, who in turn subscribe to raiser objects? Or (2) Raisers just use the static Event Manager reference directly and call a function there, which in turn fires an event to which the listeres are subscribed to?
Rethink Everything with Scriptable Object VARIABLES
15:28
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 15 МЛН
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 29 МЛН
The Ultimate Introduction to Scriptable Objects in Unity
20:45
ScriptableObjects, Explained | Unity Tutorial
19:27
LlamAcademy
Рет қаралды 13 М.
SCRIPTABLE OBJECTS and EVENTS in Unity
6:46
Root Games
Рет қаралды 7 М.
Unleashing the Power of Event Channels in Unity
21:24
git-amend
Рет қаралды 13 М.
Be CAREFUL with Scriptable Objects!
8:27
Code Monkey
Рет қаралды 85 М.
The Power of Scriptable Objects as Middle-Men
17:41
samyam
Рет қаралды 131 М.
C# Events & Delegates
17:21
Tarodev
Рет қаралды 91 М.
Unity's New Input System:  The Definitive Guide
32:07
DmanGames
Рет қаралды 34 М.
SCRIPTABLE OBJECTS in Unity
8:57
Brackeys
Рет қаралды 1 МЛН