PhotonNetwork.Destroy only working on one Client

Hey! I am trying to use PhotonNetwork.Destroy, but for some odd reason it's not quite working as I would expect. I am trying to get the MasterClient to destroy the object over the network (which is instantiated, of course) but it only seems to work on the MasterClients game as well, instead of destroying it for all players. It would be amazing if someone could help me with this issue. Thank you in advance!

Comments

  • Nobody got any ideas? The code itself is VERY simple (and actually worked on the standard Unity network solution):

    [code2=csharp]public float ExpireTime = 5.0f;
    public float Timer = 0.0f;

    // Update is called once per frame
    void Update ()
    {
    Debug.Log ("Destroying Object");
    if(PhotonNetwork.isMasterClient)
    {
    //Destroy the Object after the given Time
    if(ExpireTime > Timer)
    {
    Timer += 1 * Time.deltaTime;
    }
    if(Timer >= ExpireTime)
    {
    PhotonNetwork.Destroy (gameObject);
    Debug.Log ("Destroyed Object");
    }
    }
    }[/code2]
  • Help us help you by checking the console. If some object can't be destroyed, then we usually log some hint why.

    Aside from that: If you have some object that gets destroyed after 5 sec in any case, you can send a RPC instead of creating and destroying it, the RPC can pass 1 variable "destroyAfterSeconds" or so. Then every client already knows what to do and when.
  • This is the error that my console gives me when a none master client player instantiates a particle:
    Failed to 'network-remove' GameObject. Client is neither owner nor masterClient taking over for owner who left: View (0)2012 on BloodSplat (Expire)(Clone)

    Maybe I should also add this (another message that pops up whenever somethings supposed to be destroyed):
    Ev Destroy for viewId: 2009 sent by owner: True this client is owner: False

    I hope this is enough info! You mentioned that destroying the object via RPC would be the same as a PhotonNetwork.Destroy(), is that correct? If yes, how would you implement that? Send RPC to MasterClient who then sends it to everyone?
  • The error says it all: You try to destroy a GO that you didn't create, nor is that client the Master Client in this room.
    There is a ownership system in place to avoid issues when random people could destroy objects anytime, so only the owner should destroy a GO.

    I meant: You can sent an RPC for the shot. Any client can create a bullet and make it move. If you sent position updates for an object that moves along a straight line until it hits something, then you would do something wrong. Any client is able to simulate this, given start position, direction, velocity and maybe even time of the shot.
    The shooting user can also detect if some other was hit and send an RPC "i hit you! decrease your HP by X" to make sure every client has the same result for the bullet. Don't send "the bullet hit a wall".
  • First of, thank you for your reply. I can know what the error means, but I don't know how to fix it ^^ You are saying there is a feature on how to check who the owner is and make them destroy the GO? Show me how and I will consider the problem solved!
  • The owner is whoever Instantiated the GO in the first place. Check PhotonView.isMine.
    Please head over to the Marco Polo Tutorial. It's used and explained there:
    http://doc.exitgames.com/photon-cloud/M ... o_Tutorial
  • I am familiar with PhotonView.isMine, so this should be the final piece of code to fix everything right?

    [code2=csharp]Debug.Log ("Destroying Object");
    if(PhotonView.isMine)
    {
    //Destroy the Object after the given Time
    if(ExpireTime > Timer)
    {
    Timer += 1 * Time.deltaTime;
    }
    if(Timer >= ExpireTime)
    {
    PhotonNetwork.Destroy (gameObject);
    Debug.Log ("Destroyed Object");
    }
    }
    }[/code2]
  • I can't guarantee it but it looks good.
    I'd not use PhotonNetwork.Instantiate for bullets at all. Better use an RPC. Or: Add a bool to the stream in OnPhotonSerializeView() if you are firing. Or how often you fired, or something. And then send an RPC to actually reduce the hitpoints if you hit.