Instantiating from CoherenceSyncConfig
Last updated
Was this helpful?
Last updated
Was this helpful?
This is somewhat of an advance technique. If you're new to coherence and simply looking to instantiate an object, refer to the .
Instead of hard referencing Prefabs in your scripts to using Unity's own Instantiate()
, you can reference a CoherenceSyncConfig
and instantiate Prefab instances through our API. This will respect the custom loading and instantiation rules set on the CoherenceSync component, that is the specified in Instantiate via and the specified in the Load via properties.
In code terms, it utilizes the internal INetworkObjectProvider
and INetworkObjectInstantiator
interfaces to load and instantiate the Prefab in a given .
To instantiate a networked Prefab starting from its CoherenceSyncConfig, you simply need to invoke GetInstance()
:
You can also hard reference the Prefab in your script, and then use our CoherenceSync API to instantiate the Prefab:
While the end result is the same, the main difference is that referencing a CoherenceSyncConfig instead of a Prefab makes it a much more scalable and future-proof architecture. Since it doesn't need a Prefab hard reference, you won't have to change the code if the way that the Prefab is loaded into memory changes later on (for example, if you go from Resources to load it via Addressables).