Thanks. This is an old solution, there's a newer version that I made that is simpler to use, and I also demonstrate how to create and use the events: kzbin.info/www/bejne/fJnYfKNjmZ6Ai7Msi=VEUgn1yO07026TnR
@doancatphu69122 ай бұрын
@@LasanhaDev Thanks <3
@devdog74093 ай бұрын
I noticed you're calling the event bus directly from the class instead of creating a singleton reference or DI. Would you mind explaining to me your thought process as to how you decide on those options? I pretty much just started creating games and I read singletons can cause issues if misused so I've been trying to only use them for my managers or things like an event bus, but as I get further in, I'm starting to think I shouldn't use singletons at all. tldr: How to you decide the best way to manage dependencies?
@LasanhaDev3 ай бұрын
Sure I'll explain. I usually use static classes over common singletons for classes that needs to be available throughout the whole game, do not need an actual Object instance (meaning only static fields), and don't need scene references as dependencies. That's the opposite of the singletons, where you usually create a Instance getter and attach the component to a GameObject, meaning that is an actual object inside the scene and you can get the benefits as a normal MonoBehaviour while being able to use the DontDestroyOnLoad to keep the object alive between scenes loading. My problem with singletons is that since they are basically just a instance object with a global point, they instead of facilitating the communication between objects they are used to modify the state/data of the singleton instance, instead of just executing some logic, like the event bus invoking events (which I also don't like anymore, I'll explain), and in my opinion, that's bad. I've experienced singletons in a big project that were used like this. This can lead to issues where two objects are modifying the same data and you don't even know, meaning that if you move the line up or down, it can cause problems, and that is maintenance/expansion pain. Imagine that you need to read or write on that data. If you try to loop and the data is changed you would get a Collection Modified exception, and if you need to modify, depending on the type of data, you would need to know what objects that also modifies and when it modifies to not conflict with them. Doing this for singletons that have lots of references can cost you long debug periods. That's why for small projects/prototypes it's fine, because you usually know where it's being used and if you have problems you would be able to fix it quickly. Now for the EventBus I would recommend you stay away. This video is almost 1 year old, and I also released a new video on this 6 months ago. From that time to nowadays I've used EventBus in some projects, and from that experience I think I would never want to use it again 💀. For 2 reasons: 1 - Hard to debug: Anyone can invoke any event and since it's very decoupled you don't even know where something it's coming from. I've had a problem where I needed to basically synchronize an event that was being invoked from a async method and another from initialization from another object, you can imagine how bad the situation was. I ended up using normal object events and property binding, which I plan to make videos about it soon. But the is trying to decouple everything can end in situations like this, where you need to dig deep into the code to find where the problem actually is. 2 - Memory Leak: We are used to unity collecting the objects for us when loading scenes, but since in this implementation the EventBus is a static class, that means that the events would try to keep the objects references, so if you unload a scene and invoke the static event and didn't unsubscribed from the event, you would get a null reference exception, but the problem get more serious when you're using Non-Monobehaviour objects, meaning that the static events will keep the entire object alive until you dispose unsubscribing from the event and allowing it to be collected by the GC, that's for C#, if you're in C++ and didn't unsubscribed and don't have a way to access the object anymore, the object would remain alive throughout the whole application occupying memory and probably referencing invalid memory addresses that could potentially crash the game. The best way to manage dependencies? Honestly, I don't really know. I've been recently using DI Frameworks like Extenject and the ServiceLocator pattern to manage dependencies and found them both good solutions for this problem, but I tend to be more favorable on the DI side In one of my latest videos I used the service locator but I think I'll adapt the project to DI as it grows, but for now it's fine. In unity, even using SerializeField is a form of DI as well. Since you just started creating games, I would recommend you to just make things happen on the screen, not trying to find the best architecture, because you will probably not find a perfect one, since you will always be learning and finding different ways of doing things. Try to code a feature, and then refactor it, doing this you will be able to find the areas of improvement of your code and fix it in anyway that you decide it's more suitable. I use this approach even for complicated features, so for example instead of thinking too much and start creating abstractions for problems that don't even exist yet, just code what you need and extract the logic/abstractions from that and will get the feature working and a maintainable codebase. It’s easy to overengineer your code when trying to find the perfect solution, try to focus on the current needs of your project and refactor it as needed. That's a lot of text 🤣 but I hope you find it useful. I also recommend you take a look at this youtube channel: www.youtube.com/@ChristopherOkhravi/videos. You can search on the playlists a topic that you are interested and learn some useful stuff there. tldr: Learn to solve problems by context and you will learn a lot. Doing that you will be able to decide what's the appropriate approach for each situation or similar ones
@devdog74093 ай бұрын
@@LasanhaDev lol that is a lot of text. I will read it in pieces. Appreciate the help 🙏. Hope you do well!
@davidalejandromoralesmejia64193 ай бұрын
i need the folders, because its for develop a project in my school bro :)
@LasanhaDev3 ай бұрын
@@davidalejandromoralesmejia6419 All the resources from my videos are available on my GitHub. You can download them here: github.com/Lasanha-Dev Good luck on your school project :D
@davidalejandromoralesmejia64193 ай бұрын
can you share the assets please
@LasanhaDev3 ай бұрын
@@davidalejandromoralesmejia6419 I found the assets on the internet. But if you want, this project is available on my GitHub: github.com/Lasanha-Dev/Ghosts-n-Goblins-Unity
@vanan22354 ай бұрын
Have a good day, teacher.
@LasanhaDev4 ай бұрын
Thanks man. You too 👊
@multiverso20235 ай бұрын
Fico triste por ver um canal tão bacana ter poucos seguidores. Meu amigo você merece milhares de seguidores!
@LasanhaDev5 ай бұрын
tmj man. Acho difícil um dia bater essa marca mas quem sabe né kk tem 70 inscritos, já é bastante coisa. Eu não tenho muito tempo livre pra gravar os vídeos e editar então as frequências de vídeos acabam sendo um pouco baixas (coisa que o KZbin não gosta) e a edição acaba sendo mais cortes e ajustes de áudio msm. Mas eu curto bastante fazer esse estilo de vídeo, pq eu tb já assisti vários vídeos de outros canais pequenos na época que eu tava aprendendo que me ajudaram bastante. Então no caso eu criei esse canal pra tentar compartilhar oq eu sei e ir aprendendo tb. Tenho várias ideias de vídeos que eu quero fazer mas por enquanto o foco é essa série
@jaychau2106 ай бұрын
thanks
@vanan22356 ай бұрын
😍😍😍
@vanan22356 ай бұрын
Thanks for tutorial. I learn a lot in your video about state pattern. <3
@LasanhaDev6 ай бұрын
Thanks bro 👊
@LasanhaDev7 ай бұрын
6:12 note: This is not for just caching and speeding up access to entity components. The transitions and states are not MonoBehaviours, so they can't use GetComponent. That's the main purpose of this classto allow non MonoBehaviours classes to retrieve the StateMachine GameObject components
@shoot4rank7657 ай бұрын
Keep it up man! I learned a lot
@LasanhaDev7 ай бұрын
Thanks! Glad it helped :D
@septiannabilah47798 ай бұрын
Nice update! Btw could you share the new code ? That would be awesome.. Thank you
@LasanhaDev8 ай бұрын
I uploaded to github here: github.com/Lasanha-Dev/Unity-EventBus It's separated between 2023 and 2024, and there's also the GlobalLogger. You can modify the scripts if you want to remove the GlobalLogger from the event bus system
@septiannabilah47798 ай бұрын
@@LasanhaDev thanks a lot!
@ograpes34589 ай бұрын
Thx for the tips, what's the difference between readonly and const ? I know const but never used readonly
@LasanhaDev9 ай бұрын
Const: You can use const to declare a value at compile time that will never change during runtime. I usually use const to declare strings and remove magic numbers. In this video of the Ghosts 'n Goblins series, I use const to declare some fields inside the LadderController: kzbin.info/www/bejne/r2mUqoaXrNmYmac And also in this video of the event bus 2024 solution, I use const to declare the event names. Since the names won't change at runtime, I can create them at compilation time: kzbin.info/www/bejne/fJnYfKNjmZ6Ai7M Readonly: You can use this to initialize the variable in the object constructor or field declaration. Since the value will not change, the only thing that you will be able to do with that field is read the value. Because MonoBehaviour doesn't have constructors, you can't declare a readonly field and try to assign it during Awake or Start. So I mostly use to declare Data Structures, and also with EventBus where I need to pass some parameters I usually declare the record fields as readonly and assign them in the constructor. In this example, the animator variable is assigned in the declaration, so I can only read the generated hash value. On the Object Pooling video I use a const field to use as Default pool size and readonly for the _poolsDictionary: kzbin.info/www/bejne/q4DMiYFpoNqAaNE I reformulated a little bit the object pool class, after using for sometime I found some problems and areas to improve, so I'll make another video like the event bus but for the object pool 2024 solution. There are some other cases, which the docs explains well: Readonly: learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/readonly Const: learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/const
@multiverso202310 ай бұрын
Você fez as sprites?
@LasanhaDev10 ай бұрын
Não, as sprites eu achei na internet mas parecem ter sido extraídas direto do jogo
@multiverso202310 ай бұрын
@@LasanhaDev são maravilhosas... Coloca o endereço e vamos tentar fazer um jogo igual ao teu!
@LasanhaDev10 ай бұрын
@@multiverso2023 São bonitas mesmo mas elas foram criadas pela Capcom, essa arte é da versão Arcade do game lançado em 1985: kzbin.info/www/bejne/q3rLqp2ojbubsMk Nos vídeos eu estou apenas recriando as mecânicas de gameplay usando a Unity
@multiverso202310 ай бұрын
@@LasanhaDev muito bom! Espero que teu canal tenha muito sucesso!
@LasanhaDev10 ай бұрын
@@multiverso2023 vlw mano
@LasanhaDev Жыл бұрын
github.com/Lasanha-Dev/Unity-EventBus
@jaychau210 Жыл бұрын
I like your videos
@LasanhaDev Жыл бұрын
Thank you
@khanhhoangquoc1800 Жыл бұрын
I have a question. If i want to make player have ability like timeslow, so i need to change player to ability state but that will not call idle or movement state as well. Do u have any ideas? Sorry for my bad english
@LasanhaDev Жыл бұрын
For abilities like this, I would not use state machines because it's not something that changes the player's behavior, and like you said, you still need to call Idle or Movement. But I would still use scriptable objects with an ability class that you can use when you press the input. For example, let's say that your game has an ability system where the player can have two abilities in two slots, each with a different ability. You can associate each slot with an input, and each slot will be filled with a Scriptable Object. So when you press, for example, the key "G", you will call the ability on the first slot. If no ability is in there, okay, nothing happens. But if you got the slow time ability there and you pressed "G", then you call the ability, and the ability would do the work to slow time down, and the player state machine would still work.
@KiraYoko-wy8qi Жыл бұрын
So helpful, now I know how to use state machine , thank you very much. I hope you will finish this game in the future.
@LasanhaDev Жыл бұрын
Thank you. Yes, I'll finish this game, and I'll also use other design patterns as the game advance.
@KiraYoko-wy8qi Жыл бұрын
So interesting , it is one of my favorite games
@LasanhaDev Жыл бұрын
It's a fantastic game. Soon I'll be releasing the source code online on GitHub