Unknown Error with RPC. Bullet Destroying

Hello all, I'm having error message it's strange for me, because it seems me that script works, both players can see instantiated explosion prefab, successfully destroying bullets when collides.

Error message:

Illegal view ID:0 method: MakeExplosion GO:Bullet 1(Clone)
UnityEngine.Debug:LogError(Object)
NetworkingPeer:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3253)
PhotonNetwork:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2930)
PhotonView:RPC(String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:569)
BulletScript:OnCollisionEnter(Collision) (at Assets/Scripts/Player/BulletScript.cs:21)
_____________________________________________________________________________________________________
Warrning message:

Had to lookup view that wasn't in photonViewList: View (0)0 on Bullet 1(Clone) (scene)
UnityEngine.Debug:LogWarning(Object)
NetworkingPeer:GetPhotonView(Int32) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3013)
NetworkingPeer:ExecuteRpc(Object[], PhotonPlayer) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2289)
NetworkingPeer:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3293)
PhotonNetwork:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2930)
PhotonView:RPC(String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:569)
BulletScript:OnCollisionEnter(Collision) (at Assets/Scripts/Player/BulletScript.cs:21)
___________________________________________________________________________________________________

I have PhotonView component in my Bullet 1 prefab. Now has nothing observes. I tried to observe Transform component but error does not vanishes. So please my code:
using UnityEngine;
using System.Collections;

public class BulletScript : MonoBehaviour {

	public ParticleSystem explosion;
	private float LifeTime = 3;
	private float RespawnTime = 0;
	

	void Start () 
	{
	    
	}


	void OnCollisionEnter(Collision collision)
	{
		if (collision.gameObject.tag == "Wall") 
		{
			GetComponent<PhotonView> ().RPC ("MakeExplosion", PhotonTargets.All);
			Destroy(gameObject);
		}
	}

	[PunRPC]
	void MakeExplosion ()
	{
		ParticleSystem Clone;
		Clone = Instantiate (explosion, transform.position, transform.rotation) as ParticleSystem;
		Destroy(gameObject);
	}
	

	void Update () 
	{
		RespawnTime += Time.deltaTime;
		if(RespawnTime>LifeTime)
		{
			Destroy (gameObject);
		}
	}

}
By the way I have used same rpc method in my Shooting script. I did not get any error messages.

If you interested to see my shooting script I can post it as a comment. Please help me with this problem. Thank:smile:

Comments

  • Hi,

    It seems like the problem would be that you should destroy only if you own the GameObject, so make sure you own it before destroying it.

    Check this thread, there is a code sample at the end: http://forum.photonengine.com/discussion/4932/getting-an-error-when-photonnetwork-destroy-ing

    if(photonView.isMine) { PhotonNetwork.Destroy(gameObject); }
    And typically, you should also look for an alternative as fast bullets should not really be networked.

    Bye,

    Jean
  • Hi, first of all I would like to say Thank you Jean for taking time to read my post and trying to help me.
    But when I tried to use by your method I got next error messages. I have deleted component from the "Bullet 1" prefab. And my code looks like this:
    using UnityEngine;
    using System.Collections;
    
    public class BulletScript : MonoBehaviour {
    
    	public ParticleSystem explosion;
    	private float LifeTime = 3;
    	private float RespawnTime = 0;
    
    	public GameObject myPlayer;
    
    	void Start () 
    	{
    		myPlayer = GameObject.FindWithTag ("Player");
    	}
    
    
    	void OnCollisionEnter(Collision collision)
    	{
    		if (collision.gameObject.tag == "Wall") 
    		{
    			myPlayer.GetComponent<PhotonView> ().RPC ("MakeExplosion", PhotonTargets.All);
    		}
    	}
    
    	[PunRPC]
    	void MakeExplosion ()
    	{
    		ParticleSystem Clone;
    		Clone = Instantiate (explosion, transform.position, transform.rotation) as ParticleSystem;
    		if (myPlayer.GetComponent<PhotonView> ().isMine) 
    		{
    			PhotonNetwork.Destroy (gameObject);
    		}
    	}
    	
    
    	void Update () 
    	{
    		RespawnTime += Time.deltaTime;
    		if(RespawnTime>LifeTime)
    		{
    			if (myPlayer.GetComponent<PhotonView> ().isMine) 
    			{
    			PhotonNetwork.Destroy (gameObject);
    			}
    		}
    	}
    
    }
    Errors:
    PhotonView with ID 1001 has no method "MakeExplosion" marked with the [PunRPC](C#) or @PunRPC(JS) property! Args:
    UnityEngine.Debug:LogError(Object)
    NetworkingPeer:ExecuteRpc(Object[], PhotonPlayer) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2469)
    NetworkingPeer:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3293)
    PhotonNetwork:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2930)
    PhotonView:RPC(String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:569)
    BulletScript:OnCollisionEnter(Collision) (at Assets/Scripts/Player/BulletScript.cs:22:smile:

    Failed to 'network-remove' GameObject because has no PhotonView components: Bullet 1(Clone) (UnityEngine.GameObject)
    UnityEngine.Debug:LogError(Object)
    NetworkingPeer:RemoveInstantiatedGO(GameObject, Boolean) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2826)
    PhotonNetwork:Destroy(GameObject) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2757)
    BulletScript:Update() (at Assets/Scripts/Player/BulletScript.cs:45)

    According to this forum maybe I'm having problem with Unity version and PUN version?
    my unity 5 version is 5.2.3f1 Personal edition. PUN is new fresh.
    http://www.opsive.com/assets/UFPS/forum/index.php?p=/discussion/2462/cant-get-ufps-multiplayer-demo-to-work
  • Hi,

    I would try with Unity 5.3 just to rule this out for sure. duplicate your project so avoid problems and simply test on that duplicate.

    Are you instantiating this bullet using Photon?

    Bullet 1(Clone) is the gameobject that throws the first error about this missing RPC right? can you double check before it gets destroyed that indeed you have "BulletScript" attached to the bullet instance within the hierarchy?

    Bye,

    Jean

  • jeanfabre said:

    Hi,

    I would try with Unity 5.3 just to rule this out for sure. duplicate your project so avoid problems and simply test on that duplicate.

    Are you instantiating this bullet using Photon?

    Bullet 1(Clone) is the gameobject that throws the first error about this missing RPC right? can you double check before it gets destroyed that indeed you have "BulletScript" attached to the bullet instance within the hierarchy?

    Bye,

    Jean

    Hi Jean, I'm downloading Unity 5.3.4f1. No I don't Instantiating using Photon. I understood that PhotonNetwork.Destroy works if you instantiate by PhotonNetwork.Instantiate.
    By the way my Shooting code please:
    using UnityEngine;
    using System.Collections;
    
    public class FireScript : MonoBehaviour {
    
    
    	public Transform spawnPoint;
    	public Rigidbody fireBall;
    	public float fireBallSpeed;
    
    	public AudioClip audioShoot;
    	public ParticleSystem muzzleFlash;
    
    	//public GameObject myPlayer;
    
    	void Update () 
    	{
    	
    	}
    
    	public void Fire ()
    	{
    		GetComponent<PhotonView> ().RPC ("Fire_RPC", PhotonTargets.All);
    	}
    
    	[PunRPC]
    	void Fire_RPC ()
    	{
    		Rigidbody clone;
    		clone = Instantiate (fireBall, spawnPoint.position, spawnPoint.rotation) as Rigidbody;
    		clone.velocity = transform.forward * fireBallSpeed;
    		GetComponent<AudioSource> ().PlayOneShot (audioShoot);
    		muzzleFlash.Play ();
    	}
    }
    
  • Unity 5.3.4f1 same error:(
  • Ok,

    Can you confirm that you are not instantiating the bullet using photon but unity?

    rpc call only work on networked GameObject, so I think we have to confirm this before debugging further the rpc issue.

    second, if bullet is indeed a networked GameObject, then the destroy procedure. you should only destroy a network gameobject if you are on the masterclient, else you'll need to create an RPC to call for destroy and let the masterclient catch it and execute the destroy().

    http://forum.photonengine.com/discussion/1608/ownership-and-destroying-objects

    Bye,

    Jean
  • jeanfabre said:

    Ok,

    Can you confirm that you are not instantiating the bullet using photon but unity?

    rpc call only work on networked GameObject, so I think we have to confirm this before debugging further the rpc issue.

    second, if bullet is indeed a networked GameObject, then the destroy procedure. you should only destroy a network gameobject if you are on the masterclient, else you'll need to create an RPC to call for destroy and let the masterclient catch it and execute the destroy().

    http://forum.photonengine.com/discussion/1608/ownership-and-destroying-objects

    Bye,

    Jean

    Yes, I can confirm that I don't use "PhotonNetwork.Instantiate" to trow[to fire] the bullets. I use PunRPC to make them visible, because it's 18th Century Cannon. My empty gameObject inside Cannon model which has "Fire" script also has "PhotonView" component. I have no problem or issue with it.

    I'm having strange error and warning message, they are above. When I try to destroy bullet prefab and spawn particle effects. Yes, code is works I can destroy bullets and spawn particle FX for both players. All players can see it. But that error and warning message are annoying me and makes me worry.
    I can post my codes, because I have added destructible scene objects. I can't figure out whats going on.

    Fire script:
    using UnityEngine;
    using System.Collections;
    
    public class FireScript : MonoBehaviour {
    
    
    	public Transform spawnPoint;
    	public Rigidbody fireBall;
    	public float fireBallSpeed;
    
    	public AudioClip audioShoot;
    	public ParticleSystem muzzleFlash;
    
    	public bool allowShoot;
    	public float ShotDelay;
    
    	void Start ()
    	{
    		allowShoot = true;
    	}
    
    	void Update () 
    	{
    	
    	}
    
    	public void Fire ()
    	{
    		if (allowShoot) 
    		{
    			GetComponent<PhotonView> ().RPC ("Fire_RPC", PhotonTargets.All);
    		}
    	}
    
    	[PunRPC]
    	void Fire_RPC ()
    	{
    			Rigidbody clone;
    			clone = Instantiate (fireBall, spawnPoint.position, spawnPoint.rotation) as Rigidbody;
    			clone.velocity = transform.forward * fireBallSpeed;
    			GetComponent<AudioSource> ().PlayOneShot (audioShoot);
    			muzzleFlash.Play ();
    			allowShoot = false;
    			StartCoroutine ("Reload");
    	}
    
    	IEnumerator Reload ()
    	{
    		yield return new WaitForSeconds(ShotDelay); // waits 2 seconds
    		allowShoot = true;
    	}
    }
    
    Bullet Script:
    using UnityEngine;
    using System.Collections;
    
    public class BulletScript : MonoBehaviour {
    
    	public ParticleSystem explosion;
    	private float LifeTime = 3;
    	private float RespawnTime = 0;
    
    	public GameObject myPlayer;
    
    	void Start () 
    	{
    		myPlayer = GameObject.FindWithTag ("Player");
    	}
    
    
    	void OnCollisionEnter(Collision collision)
    	{
    		if (collision.gameObject.tag == "Wall") 
    		{
    			GetComponent<PhotonView> ().RPC ("MakeExplosion", PhotonTargets.All);
    		}
    	}
    
    	[PunRPC]
    	void MakeExplosion ()
    	{
    		ParticleSystem Clone;
    		Clone = Instantiate (explosion, transform.position, transform.rotation) as ParticleSystem;
    		Destroy (gameObject);
    	}
    	
    
    	void Update () 
    	{
    		RespawnTime += Time.deltaTime;
    		if(RespawnTime>LifeTime)
    		{
    			
    			Destroy (gameObject);
    
    		}
    	}
    
    }

    Spawn destructible scene objects script:
    using UnityEngine;
    using System.Collections;
    
    public class SpawnBuildings : MonoBehaviour {
    
    	public GameObject Building1;
    
    	public bool hasDestroyed;
    
    	void Start () 
    	{
    		Invoke ("SpawnSceneObjectBuilding", 3);
    	}
    
    	void SpawnSceneObjectBuilding ()
    	{
    		if (PhotonNetwork.isMasterClient) 
    		{
    			GameObject Building1 = (GameObject)PhotonNetwork.InstantiateSceneObject ("Building1", gameObject.transform.position, Quaternion.identity, 0, null);
    		}
    	}
  • Hi,

    I think there is a misunderstanding with PunRpc and what implies.

    you can't have an PunRPC method ( in BulletScript.cs) and not instantiate using Photon, that's not possible. you must instantiate the GameObject using BulletScript.cs using Photon, then you'll be able to use PunRPC mehods, or else, you need to find another way to communicate to BulletScript.cs to trigger an Explosion.

    Can you show me the code where you instantiate the GameObject that has this BulletScript component?

    Bye,

    Jean
  • NomadicWarrior
    edited May 2016
    Hi, Jean I already posted my scripts above. I did nothing changed yet. So please let me explain the codes.
    1)Fire_Script
    Fire_Script is attached to the empty game object which is chilled in Cannon Model. Fire_script shoots when I press the button. When I press [FIRE] UI (user interface) button Fire_Script instantiates the Gameobject which is Bullet. Empty game object also has photonView component.
    public void Fire ()
    	{
    		if (allowShoot) 
    		{
    			GetComponent<PhotonView> ().RPC ("Fire_RPC", PhotonTargets.All);
    		}
    	}
    
    	[PunRPC]
    	void Fire_RPC ()
    	{
    			Rigidbody clone;
    			clone = Instantiate (fireBall, spawnPoint.position, spawnPoint.rotation) as Rigidbody;
           }
    As you can see I'm normal instantiating without Photon.
    My Instantiated Bullet gameobject has attached "BulletScript" and photonView component.
    2) BulletScript.
    BulletScript's due are make explosion when it collides with other gameObjects and Destroy yourself.
    To get explosion and destroy yourself when it collides with other object, I have used next lines:
    void OnCollisionEnter(Collision collision)
    	{
    		if (collision.gameObject.tag == "Wall") 
    		{
    			GetComponent<PhotonView> ().RPC ("MakeExplosion", PhotonTargets.All);
    		}
    	}
    
    	[PunRPC]
    	void MakeExplosion ()
    	{
    		ParticleSystem Clone;
    		Clone = Instantiate (explosion, transform.position, transform.rotation) as ParticleSystem;
    		Destroy (gameObject);
    	}
    
    By this method my codes works. Both players can see Instantiated bullets, who shoots, destroying bullets, even explosion effects. But error comes everytime I shoot.
    Now I'm working on destructable objects. health, damage, etc
  • I can record a video and send it as a private message if you're from photon developer team. Thank you Jean.
  • Hi,

    -- I don't see where and how you are instantiating the bullet itself in any of the scripts pasted in the thread
    -- Can you confirm if indeed the bullet as a photonView component and the bulletScript attached.

    From your code, all the instantiation I see are not using Photon so far, fireball and explosion are not networked gameobject prefabs. Only "Building1" is, but it's not the bullet and it's a scene based networked GameObject

    so basically, I think there is still another piece of code you need to show me for me to get a good overview.

    The project itself would help better than a video actually, and yes, I am part of the Photon Team, you can get a confirmation from Tobias for example just to double check ( which is totally fine for me, you shoudl always be careful when sharing projects). Pm me if you are ok to share the project, I can sign nda as well.

    Bye,

    Jean