# Spawning & Despawning

When you create or destroy an object in singleplayer, it only exists on your machine. In multiplayer, all connected players need to see the same objects appear and disappear at the same time. Normally, this means you'd need separate "spawn over network" calls, server-side checks, and extra boilerplate every time you want to create an object. PurrNet removes all of that.

Spawning and Despawning in PurrNet is as easy as instantiating and destroying in Unity! If the object contains a network identity (example your own scripts or the prefab link, network transform, etc.), it will automatically be spawned for other clients.

{% embed url="<https://youtu.be/XW5T6VKkeCM>" %}

You can also easily drag and drop prefabs from your project into the scene in the Unity Editor, and it should just work as well!

Keep in mind that for spawning and despawning the [network rules](https://purrnet.gitbook.io/docs/systems-and-modules/network-manager/network-rules) need to allow your relative role to the object to spawn or despawn it. With the unsafe rules, everyone can do it.

```csharp
public NetworkIdentity myObject;
private NetworkIdentity _spawnedObject;

private void SpawnMyObject() {
    //This will auto spawn the object
    _spawnedObject = Instantiate(myObject);
    
    //This will spawn it with the ownership
    _spawnedObject.GiveOwnership(localPlayer);
}

private void DespawnMyObject() {
    //Similar to what you do in Unity, just destroy the gameobject and it'll despawn
    if(_spawnedObject)
        Destroy(_spawnedObject.gameObject);
}
```
