# Ownership

In multiplayer, you need a way to determine which player is allowed to control which object. Without ownership, either everyone can modify everything (which leads to chaos and cheating), or only the server can do anything (which makes the development loop more complex). Ownership lets you define who is "in charge" of a given object, and the networking layer can then enforce permissions based on that.

Ownership is the relation between a [player ](https://purrnet.gitbook.io/docs/terminology/playerid-client-connection)and a [Network Identity](https://purrnet.gitbook.io/docs/systems-and-modules/network-identity). Upon spawning a new Network Identity, some level of ownership exists, whether that'd be no owner meaning the server has full control, or a [player/client](https://purrnet.gitbook.io/docs/terminology/playerid-client-connection) can be the owner.

{% embed url="<https://www.youtube.com/watch?v=uHxNSCYDmao>" %}

Being the owner of a [Network Identity](https://purrnet.gitbook.io/docs/systems-and-modules/network-identity), gives you different levels of authorization, depending on the [Network Rules](https://purrnet.gitbook.io/docs/systems-and-modules/network-manager/network-rules) of the [network manager](https://purrnet.gitbook.io/docs/systems-and-modules/network-manager). Keep in mind that being the owner of a network identity, doesn't mean you are directly the owner of every identity on the object. This is a setting that is specific per [network identity](https://purrnet.gitbook.io/docs/systems-and-modules/network-identity).

You can easily change ownership on your Network Identity by calling the `GiveOwnership` method, and feeding it the [PlayerID](https://purrnet.gitbook.io/docs/terminology/playerid-client-connection) to be the new owner

```csharp
networkIdentity.GiveOwnership(newOwnerPlayerId);
```

You can easily check for ownership by simply getting the owner. Be mindful that the owner and often other PlayerID references are nullable, meaning you should check whether they have a value or not.

```csharp
if(owner.HasValue)
{
    //This object has an owner
    Debug.Log($"Owner of the object is: {owner.Value}");
}
else
{
    //This object has no owner
}

//You  can also easily check if you are the owner
if(isOwner) 
{
    //If we are here, we are the owner of the object
}
```

An easy way to check whether you have "control" of the object, meaning one of the two statements below is true:\
\- There is an owner and I am the owner\
\- There is no owner and I am the server\
Is to use the `IsController` bool.

```csharp
if(IsController)
{
    //We are either the owner, or there is no owner and we're the server
    
}
else
{
    //We are not in control of this object
}
```
