# Instantiating from CoherenceSyncConfig

{% hint style="warning" %}
This is somewhat of an advance technique. If you're new to coherence and simply looking to instantiate an object, refer to the [Instantiation page](https://docs.coherence.io/manual/networking-state-changes/instantiate-and-destroy-objects).
{% endhint %}

Instead of hard referencing Prefabs in your scripts to [instantiate them](https://docs.coherence.io/manual/networking-state-changes/instantiate-and-destroy-objects) 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 [instantiator](https://docs.coherence.io/manual/asset-management/instantiate-via) specified in **Instantiate via** and the [asset loader](https://docs.coherence.io/manual/asset-management/load-via) 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 [networked scene](#user-content-fn-1)[^1].

## Reference to the CoherenceSyncConfig

To instantiate a networked Prefab starting from its CoherenceSyncConfig, you simply need to invoke `GetInstance()`:

```csharp
using Coherence.Toolkit;
using UnityEngine;

public class CoherenceSyncConfigExample : MonoBehaviour
{
    public CoherenceSyncConfig prefabSyncConfig;
    public CoherenceBridge bridge;
    
    private CoherenceSync instance1;
    private CoherenceSync instance2;
    
    void Start()
    {
        // Load the prefab and instantiate it in the current scene
        instance1 = prefabSyncConfig.GetInstance();
        // Load the prefab and instantiate it in the specific networked scene for the given CoherenceBridge
        instance2 = prefabSyncConfig.GetInstance(bridge, Vector3.zero, Quaternion.identity);
    }
    
    private void OnDestroy()
    {
        // Instances have to be destroyed via the ReleaseInstance method, so that its destruction is handle by the 
        // internal INetworkObjectInstantiator
        prefabSyncConfig.ReleaseInstance(instance1);
        prefabSyncConfig.ReleaseInstance(instance2);
    }
}
```

## Reference to a Prefab ("hard reference")

You can also hard reference the Prefab in your script, and then use our CoherenceSync API to instantiate the Prefab:

```csharp
using Coherence.Toolkit;
using UnityEngine;

public class InstantiatorViaCoherenceSyncComponent : MonoBehaviour
{
    // Serialized prefab reference
    public CoherenceSync prefab;
    public CoherenceBridge bridge;

    private CoherenceSync instance1;
    private CoherenceSync instance2;

    void Start()
    {
        // Instantiate it in the current scene
        instance1 = prefab.GetInstance();
        // Instantiate it in the specific networked scene for the given CoherenceBridge
        instance2 = prefab.GetInstance(bridge, Vector3.zero, Quaternion.identity);
    }

    private void OnDestroy()
    {
        // Instances have to be destroyed via the ReleaseInstance method, so that its destruction is handle by the
        // internal INetworkObjectInstantiator
        instance1.ReleaseInstance();
        instance2.ReleaseInstance();
    }
}
```

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).

[^1]: A scene with a CoherenceBridge component in it.
