MENU

Fun & Interesting

Learn to Build an Advanced Event Bus | Unity Architecture

git-amend 37,590 lượt xem 1 year ago
Video Not Working? Fix It Now

Decouple your Game Objects! Create a powerful Unity Event Bus that bootstraps itself at runtime using advanced C# and Unity techniques. Discover how to execute code before your scenes load and search Unity assemblies for your code. This video will help you take your skills to the next level, even if you feel like you are still a beginner!

A custom Event Bus is great for larger or more complex projects where decoupling is essential. It helps in organizing code in a way that various parts of your system can communicate without needing to reference each other directly. This way, you can change one part of your system without having a domino effect of changes across the codebase. It can help in categorizing events, logging, and even debugging to some extent by providing a clearer overview of what's happening in your game.

Advanced Topics:
- RuntimeInitializeOnLoadMethod
- InitializeOnLoadMethod
- Type.MakeGenericType(T)
- Unity Predefined Assemblies

Many people have asked, 'Why not create an EventBus at runtime instead of bootstrapping?'

Instantiating static classes in C# has some overhead, so if you have a lot of different Events it can be beneficial to create all your Event Busses ahead of time and avoid potential problems during gameplay. Additionally, it allows you to efficiently create a list of all Busses so that you can clear statics when coming out of Play Mode, something that is not guaranteed by Unity when Domain Reload is disabled, and can cause strange behaviour and memory leaks. Furthermore, you may wish to clear them anytime, or perform other debugging or diagnostics on all instances.
See the bit about Unity statics here:
https://docs.unity3d.com/Manual/DomainReloading.html

🔔 Subscribe for more Unity Tutorials https://youtube.com/@git-amend

#unity3d #gamedev #indiedev

▬ Contents of this video ▬▬▬▬▬▬▬▬▬▬

0:00 Unity Event Bus
5:00 Assemblies Utility
8:35 Event Bus Bootstrapping
11:30 Event Bus in Action!

*Source code:* https://github.com/adammyhre/Unity-Event-Bus

Extension Methods and Utils
https://github.com/adammyhre/3D-Platformer/tree/master/Assets/_Project/Scripts/Utils

*Assets Shown In This Video* (Affiliate Links)
Odin: https://assetstore.unity.com/publishers/3727?aid=1101lw3sv
Dungeon Mason Tiny Hero Duo: (FREE): https://assetstore.unity.com/packages/3d/characters/humanoids/rpg-tiny-hero-duo-pbr-polyart-225148?aid=1101lw3sv
Chromisu: Handpainted Forest MEGA Pack https://assetstore.unity.com/packages/3d/vegetation/handpainted-forest-mega-pack-248421?aid=1101lw3sv
VFX Trees: https://assetstore.unity.com/packages/vfx/particles/environment/stylized-vfx-trees-gpu-based-effect-238647?aid=1101lw3sv
Kronnect Liquid Volume 2: https://assetstore.unity.com/packages/vfx/shaders/liquid-volume-2-249127?aid=1101lw3sv
Kronnect Cloud Shadows: https://assetstore.unity.com/packages/vfx/shaders/cloud-shadows-fx-267702?aid=1101lw3sv
Kronnect Beautify: https://assetstore.unity.com/packages/vfx/shaders/fullscreen-camera-effects/beautify-3-advanced-post-processing-233073?aid=1101lw3sv
Kyeoms Hyper Casual FX 2: https://assetstore.unity.com/packages/vfx/particles/hyper-casual-fx-pack-vol-2-245262?aid=1101lw3sv
MalberS Animations: Forest Golems: https://assetstore.unity.com/packages/3d/characters/creatures/poly-art-forest-golems-164389?aid=1101lw3sv
Archanor VFX Portals: https://assetstore.unity.com/packages/vfx/particles/spells/fantasy-portal-fx-169581?aid=1101lw3sv
SineVFX: Better Crystals https://assetstore.unity.com/packages/vfx/shaders/better-crystals-235002?aid=1101lw3sv

Unity Documentation on Predefined Assemblies: https://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html

*Follow me!*
https://linktr.ee/gitamend

Comment