send rpc from an InstantiateSceneObject

Options
how can I a send rpc from an InstantiateSceneObject?
the problem is:

masterClient player connects
InstantiateSceneObject for instantiate a enemy, health = 100
player2 connects
player2 call TakeDamage to the enemy, photonTarget.AllBufered
enemy health = 50
player2 disconnects, all rpcs are destroyed

player3 connects
enemy health = 100 <
because rpc's player2 were destroyed
---- I think this...
if I send a rpc "TakeDamage" from the enemy instantiate by InstantiateSceneObject that rpc will not destroyed if player2 disconnect, I hope
help me! :)

Comments

  • vadim
    Options
    You can switch off buffered RPC cleanup on player leave and cleanup them manually but this is not recommended. photonTarget.AllBufered itself may cause problems if there are many RPCs in buffer (and all but last are useless for health change, btw).
    Try switch off the buffering and handle OnPhotonPlayerConnected, then send RPC with current state to joined player.

    Also consider using OnPhotonSerializeView synchronization. It updates sates automatically on player join.
  • vadim
    Options
    You may also route all RPCs via master (photonTarget.MasterClient) and let master call it again as buffered. Probably that is what you are asking for. But keep in mind that master client nay disconnect too (other client will become master) with RPCs lost in result.
  • vadim wrote:
    You may also route all RPCs via master (photonTarget.MasterClient) and let master call it again as buffered. Probably that is what you are asking for. But keep in mind that master client nay disconnect too (other client will become master) with RPCs lost in result.

    yes, I tried that
    ControlZombieHealth czh = obj.GetComponent&lt;ControlZombieHealth &gt;();
    czh.photonView.RPC("TakeDamage", PhotonTargets.MasterClient, 20f);
    

    and that works fine :)
    but I have other similar problem
    How can I delete a scene gameObject? (an object that is part of the scene)
    but I got this error, when player1 destroy a scene gameObject is fine, then player2 connects and the gameObject still in scene, when player2 shoots... error
    Received RPC "TakeDamage" for viewID 1 but this PhotonView does not exist! Was remote PV. Remote called.
    I think, I could destroy the scene gameObject?
    send a rpc to the masterClient with the name of the gameObject to destroy?
    I'm trying :)
  • I fixed! I hope n_n
    &#91;RPC&#93;
    	void destroyCubeInScene()
    	{
    		if(PhotonNetwork.isMasterClient && photonView.isMine)
    		{
                            //In masterClient instance don't destroy the photonView, this allows new players to see that the cube has been destroyed, so clients destroys the cube
    			GetComponent&lt;MeshRenderer&gt;().enabled = false;
    			GetComponent&lt;BoxCollider&gt;().enabled = false;
    		}
    		else
    		{
                            //In client destroy the cube
    			Destroy(gameObject);
    		}
    	}
    
    Could you tell me what you think about this?
    is that correct?
    check it online :)
    http://cdiego.heliohost.org/_pruebas/unity/zombies/Zombies.html
  • vadim
    Options
    Normally network object should be destroyed with PhotonNetwork.Destroy() call. Did you try it for scene objects on master client?