System Locator
Class used to get game systems, using generics and then making cache of said systems.
The SystemLocator is a class used to easily find any system that has been registered on it.
It helps us avoid falling into the Singleton pattern, and does something similar to the Service Locator pattern. Also good for performance reasons, It can handle over a million calls every frame with no issues.
Using the SystemLocator
To register a new system you can call the SystemLocator.Register(this) method, it'll add that system into a dictionary of systems, preventing two of the same system from existing.
Then you can get this system from somewhere else using SystemLocator.Get<T>()
⚠️ IMPORTANT!
Note that is done automatically by classes inheriting System and NetworkedSystem. They register on Awake:
Examples
Last updated