Illegal view ID:0

Options
Ive been having a really difficult issue with photon and unity 3d that i cant seem to figure out the cause of. Im trying to make a restart function to reset the game on all clients. problem is i get this Illegal view ID:0 Error and Google has not been too helpful. my RPC and where im calling it is on the same script. i have other RPCS that are basically the same thing that work just fine.This is the code I am having problems with. OnRestartPressed is being called from a UI button.
[RPC]
	void RestartMatchRPC(){
		Time.timeScale = 1f;
		isPaused = false;
		myNetworkManager = GameObject.FindObjectOfType<NetworkManager>();
		PhotonNetwork.DestroyAll();
		myNetworkManager.OnJoinedRoom();
		Debug.Log ("RestartMatchRPC");
	}
	public void OnRestartPressed(){
		isPaused = false;
		Time.timeScale = 1f;
		if (Application.loadedLevel !=1) {
			photonView.RPC ("RestartMatchRPC", PhotonTargets.Others);
		} else { 
			Application.LoadLevel(1);
		}
	}

Comments

  • vadim
    Options
    Which line produces error and what error exactly? Is it something in your log or what? Can you copy and post error content?
  • Full error from the console:
    Illegal view ID:0 method: RestartMatchRPC GO:Heli_MP2
    UnityEngine.Debug:LogError(Object)
    NetworkingPeer:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2915)
    PhotonNetwork:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2496)
    PhotonView:RpcSecure(String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:589)
    PhotonView:RPC(String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:557)
    Pause:OnRestartPressed() (at Assets/Scripts/Pause.cs:151)
    UnityEngine.EventSystems.EventSystem:Update()
    
    The error is from the line calling the RPC. As long as i dont call it it runs fine but doesnt actually do anything when i press the button
  • vadim
    Options
    You need to check object for which you call RPC.
    Is it properly instantiated and still not destroyed?
    Is client connected to the room? RPC work in rooms only.
    What is the difference between RestartMatchRPC and RPC which works for you?
  • There is no difference between RestartMatchRPC and other RPCs that work. Client is connected to the room and even with another player in the lobby it gives same error. The object isnt deleted and it is instantiated over the network by myNetworkManager.OnJoinedRoom(). Here is the whole script. All other RPCS in it work just fine.
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    
    public class Pause : Photon.MonoBehaviour {
    	GameObject PauseMenu;
    	GameObject GunnerPauseMenu;
    	GameObject CrashText;
    	GameObject GunnerText;
    	public MouseLook MouseLookScript;
    	public bool isPilot=false;
    	public bool isMultiplayer=false;
    	public bool isPaused=false;
    	bool isCrashed=false;
    	bool gunnerCrash=false;
    	NetworkManager myNetworkManager;
    
    	void Start(){
    		if (Application.loadedLevel == 1) {
    			isMultiplayer = false;
    		} else {
    			PhotonNetwork.offlineMode=false;
    		}
    		if (myNetworkManager == null) {
    			myNetworkManager = GameObject.FindObjectOfType<NetworkManager>();
    		}
    		PauseMenu = GameObject.FindGameObjectWithTag ("PauseMenu");
    		GunnerPauseMenu = GameObject.FindGameObjectWithTag ("GunnerPause");
    		CrashText = GameObject.FindGameObjectWithTag ("CrashText");
    		GunnerText = GameObject.FindGameObjectWithTag ("GunnerText");
    		PauseMenu.SetActive (false);
    		GunnerPauseMenu.SetActive (false);
    	}
    
    	void Update () {
    		if (Input.GetKeyUp (KeyCode.Escape) && isPilot == true && isCrashed==false) {
    			if(isPaused==true){// if it is paused unpause
    				isPaused=false;
    			}else{
    				isPaused=true;
    			}
    		}
    		if (isCrashed == true) {
    			PauseMenu.SetActive (true);
    			Cursor.visible = true;
    			Cursor.lockState = CursorLockMode.None;
    			CrashText.SetActive (true);
    			if (isMultiplayer == true && Application.loadedLevel!=1) {
    				photonView.RPC ("GunnerCrash", PhotonTargets.Others);
    			} 
    		} else {
    			if(CrashText==null){
    				CrashText=GameObject.FindGameObjectWithTag("CrashText");
    			}
    			if(isPilot==true){
    				CrashText.SetActive(false);
    			}
    		}
    		if (gunnerCrash == true) {
    			GunnerPauseMenu.SetActive(true);
    			Cursor.visible = true;
    			Cursor.lockState=CursorLockMode.None;
    			GameObject.FindObjectOfType<Gunner>().enabled=false;
    			GunnerText.SetActive(true);
    			GunnerText.GetComponent<Text>().text = "You have failed this mission. Waiting on Pilot";
    		} else {
    			if(isPilot==false){
    				if(GunnerText==null){
    					GunnerText=GameObject.FindGameObjectWithTag("GunnerText");
    				}
    				GunnerText.SetActive(false);
    			}
    		}
    		if (isPilot == true && isCrashed==false) {
    			if(isPaused==false){
    				Time.timeScale=1;//get unpaused
    				PauseMenu.SetActive(false);
    				Cursor.visible = false;
    				Cursor.lockState=CursorLockMode.Locked;
    				if(isMultiplayer==true){
    					photonView.RPC("GunnerPause",PhotonTargets.Others,false);
    				}
    			}else{
    				Time.timeScale=0;//GetPaused
    				PauseMenu.SetActive(true);
    				Cursor.visible = true;
    				Cursor.lockState=CursorLockMode.None;
    				if(isMultiplayer==true){
    					photonView.RPC("GunnerPause",PhotonTargets.Others,true);
    				}
    			}
    		}
    		if (isPilot == false && isMultiplayer == true && isCrashed==false) {
    			if (isPaused == false) {
    				GunnerPauseMenu.SetActive (false);
    				MouseLookScript.enabled=true;
    				Time.timeScale = 1;
    			} else {
    				GunnerPauseMenu.SetActive (true);
    				MouseLookScript.enabled=false;
    				Time.timeScale = 0;
    			}
    		}else{
    			if(isCrashed==false && isPilot==false){
    				GunnerPauseMenu.SetActive (false);
    			}
    		}
    	}
    	public void HeliCrashed(){
    		if (isPilot == true) {
    			isCrashed = true;
    			if(isMultiplayer=true && Application.loadedLevel!=1){
    				photonView.RPC ("GunnerCrash", PhotonTargets.Others);
    			}
    		} else {
    			gunnerCrash=true;
    		}
    	}
    	[RPC]
    	void GunnerPause(bool toPause){
    		isPaused = toPause;
    	}
    	[RPC]
    	void GunnerCrash(){
    		gunnerCrash = true;
    	}
    	[RPC]
    	void RestartMatchRPC(){
    		Time.timeScale = 1f;
    		isPaused = false;
    		myNetworkManager = GameObject.FindObjectOfType<NetworkManager>();
    		PhotonNetwork.DestroyAll();
    		myNetworkManager.OnJoinedRoom();
    		Debug.Log ("RestartMatchRPC");
    	}
    
    	public void OnExitToMenuPressed(){
    		isPaused = false;
    		Time.timeScale = 1f;
    		PhotonNetwork.Disconnect ();
    		Application.LoadLevel (0);
    	}
    	public void OnExitGame(){
    		isPaused = false;
    		Application.Quit();
    	}
    	public void OnRestartPressed(){
    		isPaused = false;
    		Time.timeScale = 1f;
    		if (Application.loadedLevel !=1) {
    			 photonView.RPC ("RestartMatchRPC", PhotonTargets.Others);
    		} else { 
    			Application.LoadLevel(1);
    		}
    	}
    }
    
  • vadim
    Options
    You mean that you call photonView.RPC ("RestartMatchRPC"...) and it fails while other photonView.RPC (...) on same object work ok?
    It's impossible since error thrown even before rpc method name used in code. Check NetworkingPeer.RPC method source.
  • I figured it out. Changed the rpc line to GameObject. FindGameObjectWithTag("HelicopterPlyr"). GetPhotonView(). RPC