I’ve been fighting with Photon Unity Networking for a few days now with trying to instantiate my rocket projectile properly. I’ve been told by Tobias on the Exit Games forums that using PhotonNetwork.Instantiate is completely unnecessary (good thing, too… because it didn’t do anything) and that it’s best to just use an RPC call. I’ve tried that with this code:
void fireRocket(Vector3 bottleRocketStart,Quaternion bottleRocketRot)
{
GetComponent().RPC(“fireRocket_RPC”,PhotonTargets.MasterClient, transform.position,Quaternion.identity, nm.teamID);
GetComponent().currentItem =“”;
}
[RPC]
void fireRocket_RPC(Vector3 bottleRocketStart,Quaternion bottleRocketRot,int teamID)
{
bottleRocket =(GameObject)Instantiate(Resources.Load(“BottleRocketProjectile”), mouseWeaponOrigin.transform.position,Camera.main.transform.rotation);
bottleRocket.GetComponent().shotByPlayer = teamID;
}
This successfully spawns the rocket. However, I run into issues when trying to destroy the rocket in this script, which is attached to the rocket prefab.
voidOnCollisionEnter(Collision col)
{
if(col.gameObject.name !=“BottleRocketProjectile(Clone)”&& col.gameObject.name !=PhotonNetwork.playerName){
GetComponent().RPC(“spawnExplosion”,PhotonTargets.MasterClient);
GetComponent().RPC(“DestroyOnNetwork”,PhotonTargets.MasterClient);
}
}
[RPC]
void spawnExplosion()
{
GameObject bottleRocketSplat =(GameObject)Instantiate(Resources.Load(“BottleRocketSplat”), transform.position, transform.rotation);
}
[RPC]
publicvoidDestroyOnNetwork()
{
Destroy(gameObject);
}
The explosion is spawned, but the rocket is not destroyed. I get errors here complaining about viewIDs… which makes sense, since I’m not PhotonNetwork.Instantiating them. That’s where I’m losing track of what I’m supposed to be doing. If I’m not supposed to instantiate them on the network, how do I properly call the RPCs to handle the destruction of the rocket and instantiation of the explosion?
These are the errors I get on collision with something
Illegal view ID:0 method: spawnExplosion GO:BottleRocketProjectile(Clone)
UnityEngine.Debug:LogError(Object)
NetworkingPeer:RPC(PhotonView,String,PhotonTargets,Boolean,Object[ ])(at Assets/PhotonUnityNetworking/Plugins/PhotonNetwork/NetworkingPeer.cs:2915)
PhotonNetwork:RPC(PhotonView,String,PhotonTargets,Boolean,Object[ ])(at Assets/PhotonUnityNetworking/Plugins/PhotonNetwork/PhotonNetwork.cs:2496)
PhotonView:RpcSecure(String,PhotonTargets,Boolean,Object[ ])(at Assets/PhotonUnityNetworking/Plugins/PhotonNetwork/PhotonView.cs:589)
PhotonView:RPC(String,PhotonTargets,Object[ ])(at Assets/PhotonUnityNetworking/Plugins/PhotonNetwork/PhotonView.cs:557)
RocketInfo:OnCollisionEnter(Collision)(at Assets/RocketInfo.cs:24)
Illegal view ID:0 method:smile:estroyOnNetwork GO:BottleRocketProjectile(Clone)
UnityEngine.Debug:LogError(Object)
NetworkingPeer:RPC(PhotonView,String,PhotonTargets,Boolean,Object[ ])(at Assets/PhotonUnityNetworking/Plugins/PhotonNetwork/NetworkingPeer.cs:2915)
PhotonNetwork:RPC(PhotonView,String,PhotonTargets,Boolean,Object[ ])(at Assets/PhotonUnityNetworking/Plugins/PhotonNetwork/PhotonNetwork.cs:2496)
PhotonView:RpcSecure(String,PhotonTargets,Boolean,Object[ ])(at Assets/PhotonUnityNetworking/Plugins/PhotonNetwork/PhotonView.cs:589)
PhotonView:RPC(String,PhotonTargets,Object[ ])(at Assets/PhotonUnityNetworking/Plugins/PhotonNetwork/PhotonView.cs:557)
RocketInfo:OnCollisionEnter(Collision)(at Assets/RocketInfo.cs:25)
PhotonViewwith ID 0 has no method “DestroyOnNetwork” marked with the RPC or @RPC(JS) property! Args:
UnityEngine.Debug:LogError(Object)
NetworkingPeer:ExecuteRPC(Hashtable,PhotonPlayer)(at Assets/PhotonUnityNetworking/Plugins/PhotonNetwork/NetworkingPeer.cs:2190)
NetworkingPeer:RPC(PhotonView,String,PhotonTargets,Boolean,Object[ ])(at Assets/PhotonUnityNetworking/Plugins/PhotonNetwork/NetworkingPeer.cs:2979)
PhotonNetwork:RPC(PhotonView,String,PhotonTargets,Boolean,Object[ ])(at Assets/PhotonUnityNetworking/Plugins/PhotonNetwork/PhotonNetwork.cs:2496)
PhotonView:RpcSecure(String,PhotonTargets,Boolean,Object[ ])(at Assets/PhotonUnityNetworking/Plugins/PhotonNetwork/PhotonView.cs:589)
PhotonView:RPC(String,PhotonTargets,Object[ ])(at Assets/PhotonUnityNetworking/Plugins/PhotonNetwork/PhotonView.cs:557)
RocketInfo:OnCollisionEnter(Collision)(at Assets/RocketInfo.cs:25)
From what I’ve been reading elsewhere, the trick is to not put a PhotonView on the rocket, but I can’t grasp how to call an RPC on that gameobject if it doesn’t have a PhotonView. Anyone dealt with this before and can offer me a solution?