Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

RemoveRPCs

Discussion in 'Multiplayer' started by Caps, Apr 24, 2011.

  1. Caps

    Caps

    Joined:
    Jul 23, 2010
    Posts:
    21
    Hello everyone,

    I know this has been asked before and I've read several threads about it but I just can't get it to work correctly with what I'm trying to do.

    So I have a multi-player game where any character/client can drop his gun and pick up another one in the scene.

    I do the drop from within the character's own script:

    if (Input.GetKeyUp (KeyCode.G))
    {
    dispose_position = player_capsule.transform.position + player_capsule.transform.TransformDirection(Vector3.forward);
    GameObject ak47_new;
    ak47_new = Network.Instantiate(ak47_world, dispose_position, Quaternion.identity,0) as GameObject;
    ak47_new.GetComponent<Item_World_Script>().ammo_total = primary_weapon_ammo_total;
    ak47_new.GetComponent<Item_World_Script>().ammo_magazine = primary_weapon_ammo_magazine;
    }



    So that creates a new weapon_ak47 and sets it's current ammo (both in magazine and total available) from what the character had in his own inventory. Ok, that seems to work.

    Now, the problem is when the character tries to pick it up:

    This is the part of code on the character's script for picking up an item...

    //comes from oncontollercolliderhit
    if (item_to_collect)
    {
    if (item != null)
    {

    //tell the gun script to destroy itself...
    item.GetComponent<Item_World_Script>().destroy_item = true;
    }
    }


    So in the gun script, picked up by the character:

    //coming from character's script:
    if (destroy_item)

    {
    Network.RemoveRPCs(GetComponent<NetworkView>().viewID);
    Network.Destroy(GetComponent<NetworkView>().viewID);
    }




    Ok, so the weapon get's destroyed but for some reason wich I cannot grasp or understand yet, the RemoveRPCs is not working. So new clients that connect still see the weapon lying there...

    I'm wondering if I'm doing something really stupid here, but I'm really confused about how to manage this RemoveRPCs, unfortunatelly the docs don't provide good explanation on it.

    Would anyone please, please enlighten me on this?
     
    Last edited: Apr 24, 2011
  2. Caps

    Caps

    Joined:
    Jul 23, 2010
    Posts:
    21
    Anyone?
     
  3. Caps

    Caps

    Joined:
    Jul 23, 2010
    Posts:
    21
    Ok, let me try to put it this way.I would like to ask a few questions, maybe from the answers I might get some help...

    From what I understand, RemoveRPCs will remove all RPCs sent by a player? So, I'm thinking, if a player "netwok.instantiates" a prefab (it will send a buffered RPC for all other players of that object being instantiated).

    So, in this case, my player "network.instantiates" a prefab, all other clients can see that prefab. If another client/player picks it up then I should send a RemoveRPCs based on the player ID who instantiated that prefab?

    Another thing, if RemoveRPCs removes ALL rpcs sent by the player, how can I have it remove the RPC that instantiated the prefab only? I mean, if I use RemoveRPCs for a player that instantiated a prefab, then the player instantiation itself, for other clients, will be removed, so not only will the prefab be removed but the player who instantiated the prefab itself...

    I don't know if I'm totally lost here, I would really appreciate if someone could give me some direction, some advice on this.


    Thanks in advance,


    Best regards,
     
    Last edited: Apr 25, 2011