# Getting the local player that interacted with object

**URL:** https://discussions.unity.com/t/getting-the-local-player-that-interacted-with-object/693074
**Category:** Multiplayer & Networking
**Created:** [February 26, 2018, 9:19pm UTC](https://discussions.unity.com/t/getting-the-local-player-that-interacted-with-object/693074 "2018-02-26T21:19:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Corva-Nocta](https://avatars.discourse-cdn.com/v4/letter/c/dc4da7/32.png) [@Corva-Nocta](https://discussions.unity.com/u/Corva-Nocta)
#### Post date: [February 26, 2018, 9:19pm UTC](https://discussions.unity.com/t/getting-the-local-player-that-interacted-with-object/693074/1 "2018-02-26T21:19:27Z")

</div>

I have a few resource game objects that my players can interact with but now I need to be able to give the players items when they gather. I have a simple system where the local player gets the network id of the object then runs the necessary code to interact with that object.

My question is, how can I get the id of the player that did the interaction? Basically if a player interacts with a gameobject, how do I send that player’s network id to the gameobject so it can send back info like items that are obtained?

Any help at all would be great!

---

<div class="post-metadata">

### Author: ![Corva-Nocta](https://avatars.discourse-cdn.com/v4/letter/c/dc4da7/32.png) [@Corva-Nocta](https://discussions.unity.com/u/Corva-Nocta)
#### Post date: [February 27, 2018, 12:12am UTC](https://discussions.unity.com/t/getting-the-local-player-that-interacted-with-object/693074/2 "2018-02-27T00:12:04Z")

</div>

I know I’m close, but I’m just not sure how to put all the pieces together. I can get the Network Identity of any object, including players, by using the code:

```auto
Debug.Log (netId);

```

so I can grab the id, but I still am not sure how to send that info to the object, or how to store that info on the object.

---

<div class="post-metadata">

### Author: ![TwoTen](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/twoten/32/498699_2.png) [@TwoTen](https://discussions.unity.com/u/TwoTen)
#### Post date: [February 28, 2018, 11:34pm UTC](https://discussions.unity.com/t/getting-the-local-player-that-interacted-with-object/693074/3 "2018-02-28T23:34:26Z")

</div>

> [@Corva-Nocta](#):
>
> I know I’m close, but I’m just not sure how to put all the pieces together. I can get the Network Identity of any object, including players, by using the code:
> 
> ```auto
> Debug.Log (netId);
> 
> ```
> 
> so I can grab the id, but I still am not sure how to send that info to the object, or how to store that info on the object.

Every NetworkBehaviour has a netId field. You can grab the netId from any NetworkIdentity. NetworkIdentitys can be sent in Cmd & Rpc calls where the reciever then get find the corresponding local object on their machine.  
The netId is just a uint.

---

<div class="post-metadata">

### Author: ![Fikule](https://avatars.discourse-cdn.com/v4/letter/f/d6d6ee/32.png) [@Fikule](https://discussions.unity.com/u/Fikule)
#### Post date: [March 7, 2018, 3:24pm UTC](https://discussions.unity.com/t/getting-the-local-player-that-interacted-with-object/693074/4 "2018-03-07T15:24:04Z")

</div>

You can also just send a GameObject:

```csharp
[Command]
public void CmdSendObject(GameObject obj)

```

Objects sent like this need a NetworkIdentity, so I assume the method just does the work of sending the net id and finding the corresponding object on the receiving side.

An example for gathering:

```csharp
//(A method on the player)

public void OnPickup(GameObject obj)
{
    if (hasAuthority)
    {
        CmdPickup(obj);
    }
}

[Command]
private void CmdPickup(GameObject obj)
{
    RpcPickupObj(GameObject obj);
}

[ClientRpc]
private void RpcPickupObj(GameObject obj)
{
    if (obj.GetComponent<ItemScript>())
    {
        obj.GetComponent<ItemScript>().Pickup(this.gameobject);
    }
}

//(On ItemScript.This is on any item you can pick up)
public void Pickup(GameObject player)
{
    //Do client actions here. i.e. each client gives the player who picked it up the item on their client
    player.AddItem(new InventoryItem { some_properties = itemScriptProperties });

    if (isServer)
    {
        //Do server actions here, i.e. destroy the item on the floor
        NetworkServer.Destroy(this.gameobject);
    }
}

```
