# Spawning and Despawning

For objects to exist over the network they must have a NetworkObject component on them, and **must be spawned using the server**. To spawn an object it must first be instantiated, and then passed into a Spawn method. There are a variety of Spawn methods to access for your convenience, all of which provide the same outcome.

{% hint style="warning" %}
Networked addressable prefabs must be registered with the NetworkManager differently. See [Addressables](/docs/guides/features/addressables.md) guide for more information on this.
{% endhint %}

**Spawning without an owner** is done by passing in *null* for the owner, or simply leaving the argument out.

```csharp
GameObject go = Instantiate(_yourPrefab);
InstanceFinder.ServerManager.Spawn(go, null);
```

```csharp
GameObject go = Instantiate(_yourPrefab);
InstanceFinder.ServerManager.Spawn(go);
```

**Spawning with ownership**

```csharp
GameObject go = Instantiate(_yourPrefab);
InstanceFinder.ServerManager.Spawn(go, ownerConnection);
```

You may also access the spawn method within any script that inherits NetworkBehaviour, or by accessing the NetworkObject.

```csharp
GameObject go = Instantiate(_yourPrefab);
base.Spawn(go, ownerConnection); // networkBehaviour.
// or
networkObject.Spawn(go, ownerConnection); // referencing a NetworkObject.
```

**Despawning** can be accessed the same ways as spawning. Through a NetworkBehaviour script, a reference NetworkObject, or through the ServerManager directly.

```csharp
base.Despawn(); // networkBehaviour. Despawns the NetworkObject.
networkObject.Despawn(); // referencing a NetworkObject.
InstanceFinder.ServerManager.Despawn(gameObject); // through ServerManager.
```

When despawning you may also choose to pool the object rather than destroy it. There are optional parameters available to change this behavior.

```csharp
base.Despawn(DespawnType.Pool); // pools the object instead of destroying it.
```

You can check if an object is spawned at anytime using the *IsSpawned* property within NetworkBehaviour, or NetworkObject.

**Scene Objects** are spawned and despawned like instantiated objects, except you pass in the reference of the already instantiated/placed scene object. A scene object becomes disabled rather than destroyed when despawned.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fish-networking.gitbook.io/docs/guides/features/networked-gameobjects-and-scripts/spawning.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
