# Networked objects

> SyncVerseView, spawning and destroying, ownership, and syncing your own components.

Source: https://syncverse.aqaddoura.com/docs/networked-objects

## SyncVerseView

Every networked object has a **SyncVerseView**. It gives the object an id that is the same on every client, an owner, and a send loop. Check `view.IsMine` before acting on input.

| Setting | Default | What it does |
| --- | --- | --- |
| `Sync` | UnreliableOnChange | Off, Unreliable, UnreliableOnChange or Reliable |
| `SendRate` | 30 | State sends per second, 1–60 |
| `OwnershipTransfer` | Fixed | Fixed, Takeover or Request |

**Unreliable** means the server drops state for a receiver that is falling behind rather than queueing it; ordering is still preserved. **OnChange** skips a send when nothing changed, which keeps idle objects silent.

## Spawn and destroy

```csharp
// Prefab at Resources/Player with a SyncVerseView. The local player owns the new object.
GameObject me = room.Instantiate ("Player", spawn.position, spawn.rotation);

// Optional: let anyone take it over, and pass data every client receives.
room.Instantiate ("Ball", pos, Quaternion.identity, OwnershipMode.Takeover, new byte[] { 3 });

room.Destroy (me);   // owner or master client
```

Remote copies are created inactive, set up, then activated, so `Awake` and `Start` already see the view's owner and `InstantiationData`. When a player leaves, the objects they own are destroyed on every client.

## Scene objects

A SyncVerseView placed in a scene gets an id in the editor automatically. Scene objects always belong to the master client and cannot be destroyed over the network.

## Ownership

```csharp
// Fixed: only the owner (or the master client) can hand it over.
view.TransferOwnership (otherPlayer);

// Takeover: anyone can take it.
view.RequestOwnership ();

// Request: the owner decides.
room.OnOwnershipRequested += (view, requester) => {
    if (view.IsMine) view.TransferOwnership (requester);
};
```

Everyone gets `OnOwnershipChanged` (and `view.OnOwnerChanged`) when an owner changes.

## Built-in sync components

| Component | Syncs |
| --- | --- |
| **SyncTransform** | Position, rotation, optional scale; lerps toward the latest state and snaps past a teleport distance |
| **SyncTransformAdvanced** | Same fields with snapshot interpolation on a shared server clock and an adaptive delay |
| **SyncAnimator** | Animator parameters and layer weights |
| **SyncRigidbody** | Velocity and angular velocity |

## Sync your own state

Implement `ISyncVerseObservable` on any component of the object. The view calls it at its send rate on the owner and on every receive elsewhere.

```csharp
public class Health : MonoBehaviour, ISyncVerseObservable {
    public int Hp = 100;

    // On the owner the stream writes; on everyone else it reads. Same order both ways.
    public void OnSerializeView (SyncVerseStream stream, SyncVerseMessageInfo info) {
        stream.Serialize (ref Hp);
    }
}
```

For one-off actions (a shot, a chat line) use [RPCs](https://syncverse.aqaddoura.com/docs/rpcs) instead.
