Load via
In coherence, it's possible to specify how the Prefab for a network entity will be loaded into memory at runtime using the Load via option on the CoherenceSync
.
We support three default implementations, or you can create your own. The three default implementations are Resources, Direct Reference or Addressables, these three will be automatically managed by coherence and you won't have to worry much about them.
Resources
Resources loader will be used if your prefab is inside a Resources folder, if you wish to use any other type of loading method, you will be prompted to move the prefab outside of the Resources folder.
Direct Reference
This loader will be used if your prefab is outside of a Resources folder, and the prefab is not marked as Addressable. This means that we will need to hard reference your prefab in the CoherenceSyncConfig, which means it will always be loaded into memory from the moment you start your game.
Addressables
This option is only available if you have the Addressables Package installed.
This loader will be used if your prefab is marked as an Addressable asset, and it will be soft referenced using Addressables AssetReference class, meaning it's not loaded in memory at the beginning of the game but it gets loaded on demand, when needed.
When you choose this method, you don't have to implement Addressables code: coherence takes care of doing the loading for you, transparently.
Creating your own asset loader
You can implement the INetworkObjectProvider
interface to create your custom implementations that will be used by coherence when we need to load the prefab into memory.
Custom implementations can be Serializable and have your own custom serialized data.
Implementations of this interface will be automatically selectable via the Load via option in the CoherenceSync
for the object, or on the corresponding CoherenceSyncObject
asset.