Been learning C# on my own for a year now and so far, your videos have been the best for concise, step by step explanations. A lot of guides don't take the beginner mindset into account, and simply push forward into glossing over and including a lot of extra concepts that end up making things harder to understand. Cheers!
I don't like that either. I'm beginning to think that this channel (and others, if I'm being honest) don't think its a good idea to do the basics because it isn't sexy or too low level and boring. Which if that's the case, I disagree with wholly lol
This is the BEST Unity event tutorial I've seen so far! I've been looking around for some practical, example based tutorials for understanding both the general use case and implementation details for event systems. It's a shame I had to watch so many other tutorials before I found this one, that in 5 min covered more than the previous five tutorials I've watched combined. Keep up your good work, and THANKS for this awesome video :)
One of the clearest Dev tutors on UA-cam! I love how you anticipate questions and problems, as well as giving a bit of top-level background to the code/unity concepts you are invoking. Top job fella!
Hi, cool video, but I recommend putting the subscribe/unsubscribe lines of code in the Enable/Disable methods, because unless you call DestroyImmediate you don't really know when the object is destroyed.
I’ve been trying to achieve exactly what this video has explained for four days and not been able to until now. Earned a subscriber. First time I’ve come across your channel. Thank you!
A clear and concise video explaining events. I was self-taught with code, so I had been coding for a while before I started to understand events and how to utilise them. Even after learning about them, I still didn't really use them as I had to step out of my comfort zone. Really good explanation and usage to introduce someone to events though. Kudos!
This is an excellent tutorial. I would like to point out though that in this example you actually can eliminate the Singleton by instead making GameEvents a static class and making all its methods also static. The only times you need a Singleton are when you need to create/destroy/track runtime data/objects. If all you’re doing is managing events, you don’t need the Singleton. Hope this helps people.
Overall great tutorial. One thought, Instead of assigning a Unique ID to each script, an easier way would be to get the gameobject.InstanceID, which would save time of needing to make sure each door has a unique ID.
The id allows one trigger to open multiple doors and vice versa. + the way you suggest it doesn't work since both the trigger and the door need to have the same id.
@@Gahanun Well, good point. I made that suggestion without trying it out. However, a modification that I believe will work is if you have a parent GameObject with both the door and the trigger as children. The event system could use the transform.parent as a substitute to the ID, and simply trigger an event if the door's transform.parent is the same as the trigger's transform.parent. I can see however, that this might not be ideal for all scenarios, and simply using an ID might be the optimal solution, if the intention is to do away with directly referencing GameObjects in code.
@@qwerty81808 Without being an expert on the subject, I'd say passing the entire GameObject would be sending along far more data than is actually needed. I assume it will want to know about everything in the GameObject, so all variables and whatever, this will cause a lot of unneeded CPU instructions (reading from the RAM to get that information) when all you really need to send along is a 16-bit integer.
This was great! My computer science education is 25 years old, and I'm pretty new to C#, but I was able to follow this lesson the first time, get it all working, and understand the basics. It wasn't clear to me why we needed both the public methods and the public events defined in the GameEvents object, but a few edits to try to call the events directly from the TriggerArea objects showed me via C# errors that this isn't allowed.
Great video! Subscribed. One question: what is the difference between doing it this way and using UnityEvent and UnityAction in the UnityEngine.Events namespace?
Great video for a simple "event system"! I think it would be important to note the biggest difference between the observer pattern and an event system: An event system should be time decoupled, which your implementation is not. This means the eventsystem would have some sort of queue where events are queued, and at some later point in time the eventsystem would go through that queue and call event subscribers. A great showcase of this pattern is in the book "game programming patterns".
IMHO, the ideal scenario is that the events are handled immediately, but then the handler queues tasks. eg: void myEventHandler(int id) { StartCoroutine(DelayedHandeler(); }
@@immersiveirl6638 Starting a coroutine doesn't really do anything here. It's a bit of a misconception that coroutines are "parallel", all they do is run in the main thread until a "yield" statement tells it to stop running for this frame or for however long the yield statement tells it to. The optimal solution in Unity would be a simple queue or stack, where a "fire_event" function would add the event to the queue and the class containing the queue would work through events in its update function. The idea is to decouple heavy event handling functions from the caller, but we must also assume events can't be handled immediately. So the use-cases would be something like an achievement or sound system, where a delay of one or two frames is not noticeable. This kind of system might not, for example, work with an input system. If an event is immediately handled, it is nothing more than an observer pattern, albeit cleaner with the use of delegates and such. Nothing bad about it, just nitpicking with terminologies.
@@Xiromtz I understand that a Coroutine is not true parallelism, but dumping the task into a Queue and processing in Update is effectively the same as doing it in the EventHandler... it's still all being done in one frame. Unless you're limiting the number of tasks that get popped from the queue per Update, at which point you should probably be using a Coroutine for style (processing over multiple Updates).
@@immersiveirl6638 Oh yeah, you mean something like a coroutine that stays alive for the whole duration of execution? I did something similar once and you would be correct, that does sound like the cleaner solution. Using a time budget per frame and thend yielding until the next once the budget is expended sounds like a really good implementation.
About Unity Events not depending on each other. I heard the same thing about Scriptable Objects, so that if you delete or disable the player or an enemy then your inventory doesn't go bonkers cause the player holds the code and variables to the inventory. Instead it's put in a Scriptable Object that's open to everyone to read from, making it much more flexible and easier to access without getting any errors while changing or testing new things
So if we have 1000 doors the event is send to all doors and not to the exact door, is this not resource wasteful as the event is relevant to only specific door, every door has to process the event and react if that event is relevant to it.
Is it better to use "id" to identify which door was being referenced in the event rather than just passing in the door object itself and comparing objects?
Is there was a way to automatically unsuscribe all events when destroying the object? As a codebase grows bigger, multiple people work on it, and several iterations happen, it might be easy to forget to unsuscribe an event. And is a bug that might go unnoticed for a while Does someone have a trick to do this? Thanks
It's great, however, in this particular example with doors, why just not check if some object is entering trigger of the door in the door script, maybe check the tag (ex. player) and open door from that. I think it's easier to make a door system without events Anyone, who thinks it's not the case, please comment, I want to hear opinions of other people
I'm new to Unity, but I'm watching lots of different tutorials and going through an osmosis phase in my learning. Can someone explain the difference between doing this vs using scriptable objects? Thanks!
i am already using this approach, it also saves me from so many lines of codes, But i bet you, with 50 of such Events, its becomes brain nerves tangling Nightmare, i myself keeps forgetting what event dose what sometimes, may be lack of project Documentation is the problem, but anyway this is the best approach i know, however instead of singleton, i do just parent the event class to all the classes in my project with events as static, (event class ofc getting the monobehavour class) not sure which way is the "right", let me know :)
I had an issue with Action, the error said: "the type or namespace name could not be found" To fix this I went into my code replaced all my Action namespaces with UnityAction and that fixed it. Also it took me so many rewatches to figure out that it was a captial Y in leantween movelocalY. Probably really basic, but in case anyone else had the issue hopefully this will save the all the searching I did :)
@@asclepiiusunknown1090 LeanTween is an animation engine. It is free on the asset store, just download and import it through the assets tab on unity. From there it should just work. If not try then try this: Put // in front of your leantween code so it won't activate (this is done so you are able to play game without compiler errors preventing you), press play in your game and then stop, take away the // you added prior, then it should hopefully work. This essentially refreshes the system to activate it. Also! This 2min video has a great explanation of what it is and how to use it. ua-cam.com/video/3lnViPYBHxU/v-deo.html
I've been coding for decades. I've watched tons of videos trying to convince myself of why I would use singletons over static properties and methods or why I would use a complicated event system over direct calls that make my code easy to follow and know what is happening. I still have no idea why. I could maybe see events if I was working on a large team and needed to be more modular, but working alone it still seems like adding complexity just to make my code harder to follow. I don't want to be triggering events I can't see in the triggering code. I just don't think I'll ever be convinced. In fact, if I remove code I WANT it to break so I know what's depending on it and how it needs to change. This all seems the opposite of how I want things to work.
This causes memory leaks unless you unsubscribe to the events when the object gets destroyed. One thing to remember is, for every += (event subscription) you must have a corresponding -= (event unsubscription).
That's a good example! But what would happen if we have more doors with DoorController script? Everytime OnDoorWayTrigger invoked.. Well. I got the answer here! Having an ID! I really had hard times using a static event with multiple objects. But ID really helps us in here. Any other approach maybe?
Isn't there any way to automate the id ? maybe in the door script there could be a static int currentId and in the start() you assign that id to the door and to the trigger brother, and do currentId++ would that work? would that create other problems?
As a matter of fact, you don’t pass the object, you pass a reference to that object which is just an Int! Then in your code you can say if the passing parameter is equal to “this” then do something .
Actually it's not an Event System. It's a singleton with hardcoded explicit game events. It's suitable for an examples like this one or for fast prototyping. But the name you did pick right - GameEvents, that is exactly what it is.
Hey there! Just wanted to say that this was very useful for me with my game project. I'm making a mobile game, I wanted to write my own InputManager for handling inputs. I kinda changed the way you did the system: Instead of calling the InputManager methods in the button script and subscribing to InputManager methods in like the weapon script, InputManager subscribes to all the buttons in a scene and calls the methods according to the buttons name. I think this works because the methods I want to call are mostly all tied to the Player object. But this way, my button and weapon scripts are independent of each other. I can later add gamepad support easily. Sorry for the long comment. Again, thanks for this video! I love all your videos, keep them coming!
1. The way i see it this is a great way to have a mega class. 2. Every door is now more complex than it has to be requiring a trigger that works externally to the door and an id, triggers that require you to manage them by subscribing and unsubscribing. 3. Creating calls that do nothing to doors that don't match the id and also triggers that for some reason access global door events. How is this any better than using a door (object with "open" and "closed") class that uses a trigger type. Trigger type would just handle different "activations" (enter, enter and click use button, some other item enter, etc what ever you need). This kind of approach makes it easier to maintain (changing doors has no chance of breaking other things that interact with a global mega class) because it's a closed system. Makes it easier to add into game (no need to assign an id). Adding new things doesn't require working with a mega events class which makes it A LOT easier.
Hi, I need help! when I follow the tutorial, and when I type LeanTween it won't turn to green? I am new to Unity and I don't know why is it doing that! I really appreciate the help.
I have a dilemma. Most other tutorials assign functions to actions in OnEnable(), but you assigned it in Start(). If I try to assign it in OnEnable() I get an null exception error. Why is that? Ah yes and I only get error when I have multiple doors. (I can use Start( )+OnEnable( ) together and it will work perfectly, I can disable and enable doors, but it will throw an error in the beginning)
Small tip to sweet things up: You can use onDoorwayTriggerEnter?.Invoke() as shorthand for if(onDoorwayTriggerEnter != null) { onDoorwayTriggerEnter() } With best regards from Phodex Games :) P.S.: I have not tried this with events yet, because I usually use delegates. They work pretty much the same, so you may need to switch to them to get this working.
Instead of manually assigning an ID for every door, why not pass the DoorController component directly to the event system? This would mean it would always work, no chance of accidentally reusing the same ID causing multiple doors to open at once when you enter the trigger, and less work for the developer to maintain.
for in unity in console it is showing as Assets\Scripts\GameEvents.cs(14,18): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?) what to do for this please tell?
Been learning C# on my own for a year now and so far, your videos have been the best for concise, step by step explanations. A lot of guides don't take the beginner mindset into account, and simply push forward into glossing over and including a lot of extra concepts that end up making things harder to understand. Cheers!
I don't like that either. I'm beginning to think that this channel (and others, if I'm being honest) don't think its a good idea to do the basics because it isn't sexy or too low level and boring. Which if that's the case, I disagree with wholly lol
I've been watching videos on events for days and this is the only video that actually explained it well enough for me to understand, thank you!
This is the BEST Unity event tutorial I've seen so far! I've been looking around for some practical, example based tutorials for understanding both the general use case and implementation details for event systems. It's a shame I had to watch so many other tutorials before I found this one, that in 5 min covered more than the previous five tutorials I've watched combined. Keep up your good work, and THANKS for this awesome video :)
Utterly fantastic, most tutorials available on youtube have serious pacing and clarity issues, and yet you made it look effortless.
"An object known of as the subject"
*distant linguistical screeching*
"public event Action onDoorwayTriggerEnter" Is yielding an error for me.
One of the clearest Dev tutors on UA-cam!
I love how you anticipate questions and problems, as well as giving a bit of top-level background to the code/unity concepts you are invoking. Top job fella!
Welp, this was one of the most helpful videos for GameDev in unity. Clean, fast and simple tutorial. Great job!
he goes faster than a minecraft dream speedrun but it's very helpful!
Hi, cool video, but I recommend putting the subscribe/unsubscribe lines of code in the Enable/Disable methods, because unless you call DestroyImmediate you don't really know when the object is destroyed.
It's truly astounding how easy the internet makes learning these days. Thanks for the tutorial, my guy.
This stuff is gold! I've watched a handful of your videos now and I'm astounded by how useful they are.
Please keep up the good work.
I’ve been trying to achieve exactly what this video has explained for four days and not been able to until now. Earned a subscriber. First time I’ve come across your channel. Thank you!
A clear and concise video explaining events. I was self-taught with code, so I had been coding for a while before I started to understand events and how to utilise them. Even after learning about them, I still didn't really use them as I had to step out of my comfort zone. Really good explanation and usage to introduce someone to events though. Kudos!
I FINALLY UNDERSTAND HOW TO CREATE AN EVENT SYSTEM THANKS TO YOU (All Caps intended) 😍😎💯💯
IT WORKED, THANKS I'VE BEEN LOOKING FOR THIS FOREVER, BUT NO TUTORIAL COULD EXPLAIN IT AS YOU DID
This is an excellent tutorial. I would like to point out though that in this example you actually can eliminate the Singleton by instead making GameEvents a static class and making all its methods also static. The only times you need a Singleton are when you need to create/destroy/track runtime data/objects. If all you’re doing is managing events, you don’t need the Singleton. Hope this helps people.
This was great. To the point. Quick typing. No extra fluff. Loooove it.
Overall great tutorial. One thought, Instead of assigning a Unique ID to each script, an easier way would be to get the gameobject.InstanceID, which would save time of needing to make sure each door has a unique ID.
yes that's what I thought
Why bother with any of that? Why not simply pass the GameObject or Component calling the event as a parameter?
The id allows one trigger to open multiple doors and vice versa. + the way you suggest it doesn't work since both the trigger and the door need to have the same id.
@@Gahanun Well, good point. I made that suggestion without trying it out. However, a modification that I believe will work is if you have a parent GameObject with both the door and the trigger as children. The event system could use the transform.parent as a substitute to the ID, and simply trigger an event if the door's transform.parent is the same as the trigger's transform.parent. I can see however, that this might not be ideal for all scenarios, and simply using an ID might be the optimal solution, if the intention is to do away with directly referencing GameObjects in code.
@@qwerty81808 Without being an expert on the subject, I'd say passing the entire GameObject would be sending along far more data than is actually needed. I assume it will want to know about everything in the GameObject, so all variables and whatever, this will cause a lot of unneeded CPU instructions (reading from the RAM to get that information) when all you really need to send along is a 16-bit integer.
love the video format! I appreciate you speeding up the coding sections and highlighting actual gameplay functionality.
Just found this channel. There is a lot to learn from you. :)
Maybe I am a bit late to thank you, but your video saved me hours of suffering... Thanks a lot! Keep up your good work!
I was looking for months like a tutorial like this. everyone shows an example which makes no sense or don't give even a good example. thanks
I'm working on a project right now and this video really saved me! Thank you so much!
This was great! My computer science education is 25 years old, and I'm pretty new to C#, but I was able to follow this lesson the first time, get it all working, and understand the basics.
It wasn't clear to me why we needed both the public methods and the public events defined in the GameEvents object, but a few edits to try to call the events directly from the TriggerArea objects showed me via C# errors that this isn't allowed.
Heaps of thanks, I figure it out! Please make more of these! This helps me in my assignment.
What a great video mate. Love how you've animated it to keep it interesting. Cheers
This really made the way event systems work a lot more clear for me. Thanks a lot, hope you have a good day!
You can use the UnityEvent class to benefit from automatic Unity serialization, as well as null protection if your GameObject was destroyed.
Great video! Subscribed. One question: what is the difference between doing it this way and using UnityEvent and UnityAction in the UnityEngine.Events namespace?
Wow, what a clear, concise, and informative video. Absolutely amazing work, thank you!!!
Something I've been trying to confused how to do for long time. Thank you! Subscribed
Your tutorials are so simple and understandable, keep doing this!
if brackeys and such are 10/10 this is 11/5 tbh.. these have helped me so much more with critical things than those channels have :)
Great video for a simple "event system"! I think it would be important to note the biggest difference between the observer pattern and an event system: An event system should be time decoupled, which your implementation is not. This means the eventsystem would have some sort of queue where events are queued, and at some later point in time the eventsystem would go through that queue and call event subscribers. A great showcase of this pattern is in the book "game programming patterns".
IMHO, the ideal scenario is that the events are handled immediately, but then the handler queues tasks.
eg: void myEventHandler(int id) { StartCoroutine(DelayedHandeler(); }
@@immersiveirl6638 Starting a coroutine doesn't really do anything here. It's a bit of a misconception that coroutines are "parallel", all they do is run in the main thread until a "yield" statement tells it to stop running for this frame or for however long the yield statement tells it to.
The optimal solution in Unity would be a simple queue or stack, where a "fire_event" function would add the event to the queue and the class containing the queue would work through events in its update function.
The idea is to decouple heavy event handling functions from the caller, but we must also assume events can't be handled immediately. So the use-cases would be something like an achievement or sound system, where a delay of one or two frames is not noticeable. This kind of system might not, for example, work with an input system.
If an event is immediately handled, it is nothing more than an observer pattern, albeit cleaner with the use of delegates and such. Nothing bad about it, just nitpicking with terminologies.
@@Xiromtz I understand that a Coroutine is not true parallelism, but dumping the task into a Queue and processing in Update is effectively the same as doing it in the EventHandler... it's still all being done in one frame. Unless you're limiting the number of tasks that get popped from the queue per Update, at which point you should probably be using a Coroutine for style (processing over multiple Updates).
@@immersiveirl6638 Oh yeah, you mean something like a coroutine that stays alive for the whole duration of execution? I did something similar once and you would be correct, that does sound like the cleaner solution. Using a time budget per frame and thend yielding until the next once the budget is expended sounds like a really good implementation.
Thanks a lot! Managed to make a similar thing in Javascript thanks to this tutorial!
that was the funniest unity tutorial video i have ever seen :D
I love you
About Unity Events not depending on each other.
I heard the same thing about Scriptable Objects, so that if you delete or disable the player or an enemy then your inventory doesn't go bonkers cause the player holds the code and variables to the inventory. Instead it's put in a Scriptable Object that's open to everyone to read from, making it much more flexible and easier to access without getting any errors while changing or testing new things
Hola! Espero que traduzcas esto y sepas que te quiero mucho, estoy muy agradecido por este gran video
Very good explanation!
I spent 13 seconds in this video. Liked the video..subbed and made a comment
So if we have 1000 doors the event is send to all doors and not to the exact door, is this not resource wasteful as the event is relevant to only specific door, every door has to process the event and react if that event is relevant to it.
No words. Perfect
Is it better to use "id" to identify which door was being referenced in the event rather than just passing in the door object itself and comparing objects?
Is there was a way to automatically unsuscribe all events when destroying the object? As a codebase grows bigger, multiple people work on it, and several iterations happen, it might be easy to forget to unsuscribe an event. And is a bug that might go unnoticed for a while
Does someone have a trick to do this? Thanks
stumble upon this today. Insta sub. Great job.
Why this instead of a script that manage each door locally?
Like : (OnTriggerEnter > open the door // OnTriggerExit > close the door) et voilà ?
Thanks, you explained everything well :)
i need to do this more
Incredible tutorial. Thanks!
Thx! I liked this video a lot
Great job ❤️ Big thanks!
Very proffesional and very helpful video. Thanx :)
Excellent tutorial
Before i used coroutines but now have been using event system as its more reliable to use
That was very informative, thank you
It's great, however, in this particular example with doors, why just not check if some object is entering trigger of the door in the door script, maybe check the tag (ex. player) and open door from that.
I think it's easier to make a door system without events
Anyone, who thinks it's not the case, please comment, I want to hear opinions of other people
thanks for the tutorial you are awesome!
I'm new to Unity, but I'm watching lots of different tutorials and going through an osmosis phase in my learning. Can someone explain the difference between doing this vs using scriptable objects? Thanks!
scriptable objects are a completely different thing , to my knowledge
Cool this video is amazing pretty simple and clear
i am already using this approach, it also saves me from so many lines of codes, But i bet you, with 50 of such Events, its becomes brain nerves tangling Nightmare, i myself keeps forgetting what event dose what sometimes, may be lack of project Documentation is the problem, but anyway this is the best approach i know, however instead of singleton, i do just parent the event class to all the classes in my project with events as static, (event class ofc getting the monobehavour class) not sure which way is the "right", let me know :)
I had an issue with Action, the error said:
"the type or namespace name could not be found"
To fix this I went into my code replaced all my Action namespaces with UnityAction and that fixed it.
Also it took me so many rewatches to figure out that it was a captial Y in leantween movelocalY.
Probably really basic, but in case anyone else had the issue hopefully this will save the all the searching I did :)
Hey, what is LeanTween and how can I access it cause my code editor and unity both say it doesn't exist?
@@asclepiiusunknown1090 LeanTween is an animation engine. It is free on the asset store, just download and import it through the assets tab on unity. From there it should just work. If not try then try this:
Put // in front of your leantween code so it won't activate (this is done so you are able to play game without compiler errors preventing you), press play in your game and then stop, take away the // you added prior, then it should hopefully work. This essentially refreshes the system to activate it.
Also! This 2min video has a great explanation of what it is and how to use it. ua-cam.com/video/3lnViPYBHxU/v-deo.html
Once I Get In The Top Ten s Your My Credit ;)
I've been coding for decades. I've watched tons of videos trying to convince myself of why I would use singletons over static properties and methods or why I would use a complicated event system over direct calls that make my code easy to follow and know what is happening. I still have no idea why. I could maybe see events if I was working on a large team and needed to be more modular, but working alone it still seems like adding complexity just to make my code harder to follow. I don't want to be triggering events I can't see in the triggering code. I just don't think I'll ever be convinced. In fact, if I remove code I WANT it to break so I know what's depending on it and how it needs to change. This all seems the opposite of how I want things to work.
Great video!
Great Tutorial. Thanks
THANK YOU SO M,UCH!
Thanks for this great helpful video. The code "LeanTween" is not recognized for me!! Can someone help me how to fix the error?
This causes memory leaks unless you unsubscribe to the events when the object gets destroyed. One thing to remember is, for every += (event subscription) you must have a corresponding -= (event unsubscription).
That's a good example! But what would happen if we have more doors with DoorController script? Everytime OnDoorWayTrigger invoked.. Well. I got the answer here! Having an ID! I really had hard times using a static event with multiple objects. But ID really helps us in here. Any other approach maybe?
Isn't there any way to automate the id ? maybe in the door script there could be a static int currentId and in the start() you assign that id to the door and to the trigger brother, and do currentId++
would that work? would that create other problems?
Can u explain why do I need to use this instead of mere Unity OnTrigger() methods?
Instead of doing an int id, could you just pass a reference to the object? Or is that too expensive?
As a matter of fact, you don’t pass the object, you pass a reference to that object which is just an Int!
Then in your code you can say if the passing parameter is equal to “this” then do something .
Actually it's not an Event System. It's a singleton with hardcoded explicit game events. It's suitable for an examples like this one or for fast prototyping. But the name you did pick right - GameEvents, that is exactly what it is.
Hey there! Just wanted to say that this was very useful for me with my game project. I'm making a mobile game, I wanted to write my own InputManager for handling inputs. I kinda changed the way you did the system: Instead of calling the InputManager methods in the button script and subscribing to InputManager methods in like the weapon script, InputManager subscribes to all the buttons in a scene and calls the methods according to the buttons name. I think this works because the methods I want to call are mostly all tied to the Player object. But this way, my button and weapon scripts are independent of each other. I can later add gamepad support easily.
Sorry for the long comment. Again, thanks for this video! I love all your videos, keep them coming!
u saved my life
tNice tutorialng ♂️. And I haven't used soft soft 9 since 09. So sorry bud✌ peace from Germany...
1. The way i see it this is a great way to have a mega class.
2. Every door is now more complex than it has to be requiring a trigger that works externally to the door and an id, triggers that require you to manage them by subscribing and unsubscribing.
3. Creating calls that do nothing to doors that don't match the id and also triggers that for some reason access global door events.
How is this any better than using a door (object with "open" and "closed") class that uses a trigger type. Trigger type would just handle different "activations" (enter, enter and click use button, some other item enter, etc what ever you need). This kind of approach makes it easier to maintain (changing doors has no chance of breaking other things that interact with a global mega class) because it's a closed system. Makes it easier to add into game (no need to assign an id). Adding new things doesn't require working with a mega events class which makes it A LOT easier.
Thank you!
thank you so much
This is gold
I just implemented this in my custom game engine in C++. Really well explained!
thanks a lot for this !
Hi, I need help! when I follow the tutorial, and when I type LeanTween it won't turn to green? I am new to Unity and I don't know why is it doing that! I really appreciate the help.
Open unity assets store then search for LeanTween, click download and then click import: Done.
@@suhailig-tab7573 Thanks heaps mate!
why do I keep getting null reference while trying to subscribe to a event?
For the id can't you just use the GameObject's unique instance id (GetInstanceID) instead of a magic number int?
how did you make the cube controller?
I have a dilemma. Most other tutorials assign functions to actions in OnEnable(), but you assigned it in Start(). If I try to assign it in OnEnable() I get an null exception error. Why is that?
Ah yes and I only get error when I have multiple doors. (I can use Start( )+OnEnable( ) together and it will work perfectly, I can disable and enable doors, but it will throw an error in the beginning)
How do you achieve those colors?
Small tip to sweet things up: You can use onDoorwayTriggerEnter?.Invoke() as shorthand for if(onDoorwayTriggerEnter != null) { onDoorwayTriggerEnter() }
With best regards from Phodex Games :)
P.S.: I have not tried this with events yet, because I usually use delegates. They work pretty much the same, so you may need to switch to them to get this working.
Instead of manually assigning an ID for every door, why not pass the DoorController component directly to the event system? This would mean it would always work, no chance of accidentally reusing the same ID causing multiple doors to open at once when you enter the trigger, and less work for the developer to maintain.
Why am I getting a NullReferenceException on GameEvents.current.OnDoorwayTriggerEnter += OnDoorwayOpen; ?
wow I will see that again to understand well.
Very powerful
Is it good practice to add your own event system on a system that already has one? Or is it just assuming there isn't one in unity already?
for in unity in console it is showing as
Assets\Scripts\GameEvents.cs(14,18): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)
what to do for this please tell?
Add using System; to the script
I just use if null, return checks
This is really good, Can you tell me what font you use in this video?
The font used across the channel and videos is called Korelev.
@@GameDevGuide Thank you!
HQ and Great Tuto.