Our great sponsors
-
- Implement a mediator pattern to have loose coupling and inject it through constructor as well. ( example of a library that does this for business application https://github.com/jbogard/MediatR, not sure if it's wise to use this for games, but the idea is solid). CombatManager can publish messages on the mediator, and interested entities can listen to those messages.
-
Messenger
My implementation of messenger pattern without GCAllocation and performance of 1.7 ms for 100 senders and 10 000 listeners (by Wokarol)
I haven't fully read through everything, but if you want to avoid hard references to objects and still be able to communicate, you can use messaging. Now, I wouldn't recommend Unity's SendMessage as it's pretty slow and also not type safe (you just pass a string as parameter), but you can find libraries that handle it in a more safe and efficient way. I really like this one, which combines the mediator and the observer pattern. Every object that either wants to send or receive messages just needs a reference to the same messenger object. The library offers a global static instance that you can use like you use singletons, but you can also create instances for more local scopes. I wrote more about it here in this comment:
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.