Objects not destroying
Hi! I am making an enemy that throws buff potions to other enemies in my multiplayer game. The potions work like this: The potion enemy instantiates a potion -> when hitting a wall or another enemy the potion will destroys itself with PhotonNetwork.Destroy() function and it will instantiate a prefab with a particle system.
The issue that I am having is that the particle system object does not destroy and it makes this error:
Illegal view ID:0 method: DestroyThis GO:potion splash radius(Clone) UnityEngine.Debug:LogError (object) Photon.Pun.PhotonNetwork:RPC (Photon.Pun.PhotonView,string,Photon.Pun.RpcTarget,Photon.Realtime.Player,bool,object[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1201) Photon.Pun.PhotonNetwork:RPC (Photon.Pun.PhotonView,string,Photon.Pun.RpcTarget,bool,object[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:2907) Photon.Pun.PhotonView:RPC (string,Photon.Pun.RpcTarget,object[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:604) PotionSplashScript:Update () (at Assets/PotionSplashScript.cs:28)
The PotionSplashScript looks like this:
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; public class PotionSplashScript : MonoBehaviourPun { public ParticleSystem ps; // Start is called before the first frame update void Start() { ps = GetComponent<ParticleSystem>(); } [PunRPC] void DestroyThis() { if(photonView.IsMine) PhotonNetwork.Destroy(gameObject); } // Update is called once per frame void Update() { if (ps.isEmitting) { photonView.RPC("DestroyThis", RpcTarget.All); } } }
I'd greatly appreciate any help to this problem. :)
Best Answer
-
I fixed it. The problem that I had was that I used Instantiate to spawn the potion splash prefab instead of PhotonView.Instantiate. That caused that the potion splash's photon view didn't have a owner. Thank you anyway! (by the way the definition of the photon view comes from the MonoBehaviourPun)
0
Answers
-
Hello, I am a student studying.
There seems to be no photonview specific definition and initialization syntax.
private PhotonView photonView; private void Awake() { photonView = GetComponent<PhotonView>(); }
-1 -
I fixed it. The problem that I had was that I used Instantiate to spawn the potion splash prefab instead of PhotonView.Instantiate. That caused that the potion splash's photon view didn't have a owner. Thank you anyway! (by the way the definition of the photon view comes from the MonoBehaviourPun)
0