Ownership of instances, destruction, and speed

Hello :D

So, I am attempting to set up a multiplayer game (duh :lol: ) that allows players to spawn and destroy objects. It needs to run in the Photon Cloud.

I am getting some weirdness, however.

In my test scene, the game starts and there is a cube hovering in the air that the players can shoot. If any player except for the first player (the one that started the game) shoots the cube, it stays there and I get an error that I cannot destroy objects that do not belong to me.

Well this is all fine and good but, how should I go about working around this? It is important that it run in the cloud.

I did a search and all I could find was this: http://forum.exitgames.com/viewtopic.php?f=17&t=1608&hilit=destroy

This does not suit my issue however, since it takes too long for data to get from the client, to the server, to the master client, back to the server, then back to all other clients because my game is fast-paced. I am worried that with such a solution, over time performance will degrade as RPCs get backed up and clog up the system especially in a larger game. Even if RPCs don't get backed up badly, many players will experience frustration as their apparent hit was not registered. Due to distance, speed, and the nature of gameplay, bullets are not represented as a simple raycast, instead they are represented as a rigidbody that performs a linecast between it's position and previous position during each fixed update loop. It is imperative that if a client sees a hit on their machine, the object they hit is damaged or destroyed instantly.

In addition to that, I need the hit detection and object destruction to occur very quickly without visible lag to the clients, even at the expense of cheating protection. So, it is important that the client be able to destroy any object that passes basic local checks with as little round-trip time as possible. The clients and objects are moving as fast as is reasonably possible in a networked game.

Finally, the important portion of code, the NetworkDestructibleObject class:
using UnityEngine;
using System.Collections;

[RequireComponent (typeof(PhotonView))]
[RequireComponent (typeof(Rigidbody))]
public class NetworkDestructibleObject : MonoBehaviour {
	public float health = 100;
	public PhotonView photonView;
	public PhotonViewID photonViewID;
	void Start () {
		photonView = PhotonView.Get(this);
		photonViewID = photonView.viewID;
		Debug.Log("My view ID is: " + photonViewID);
	void Damage(float dmg, PhotonViewID target, PhotonMessageInfo info) {
		Debug.Log ("RPC Recieved");
		if (target == this.photonViewID) {
			Debug.Log("Did damage to ID: " + target);
			health -= dmg;
			if (health <= 0)
	public void Hit(float dmg, PhotonViewID target) {
		photonView.RPC("Damage",PhotonTargets.All, dmg, target);
	void KillDestructible() {


  • The PUN system is sadly not built to be that flexible.
    If you want to get around the roundtrip to the owner before destroying an object, then take over control of all objects.

    What I mean:
    You can instantiate objects in your code and don't use PhotonNetwork.Instantiate, aside from the scene object to send RPCs. When a client creates or destroys a object, send the respective RPC with your own ID, etc. This means you have to know all your entities and find a way to sync exiting ones to players that are joining late.
    You could also use the plain Photon Unity API for that. It's probably less clutter and less to work around.
    Get it as Photon Unity SDK here: http://www.exitgames.com/Download/Photon

    Or you could modify the PUN code to ignore ownership. The whole logic is there as code.
Sign In or Register to comment.