8th week, Unity dependency problem. and update!


Hi Guys!

We made 2~3 UI candidates in last week.
Finally, We choose this layout for the inventory.


We felt that designing was always hard!

Today, Let we talk about how to avoid the dependency problem on our game.

Unity has the event system, and component system to communicate between classes.
however, We always get "NULL Reference Exception" 


We should avoid that terrible situation!
We saw many teams use "Singleton" pattern or "Dependency Injection". 
But, these solutions ware not perfect. 

- Hard using
or
- Memory issues
- Event naming duplicated etc :(

our solution was a delegate to store the event listener and dispatcher.

1st, We made some enum data.


2nd, made the simple event manager with a singleton pattern.

It is very simple. When some logic trigger dispatch with the key, it will trigger registered events. 
* IMessage class is the empty interface. 

and When the game object had spawning, this object will call "AddEvent" method.


When this object became disabled, We must release the event from the event manager.

When we need to trigger a specific event, We just call "Dispatch"


this solution doesn't make the null exceptions more time!

We hope this tip to help your clean atchitecture. 

See you next week!!

Leave a comment

Log in with itch.io to leave a comment.