Photon destroy the network instantiate

Options
good evening, from a few days I have a bug in my game, quickly, I shoot, the bullet should appear in all the instances of the game, but instead of creating the bullet in the other customer, the other customer sees destroyed the another player "the one who shot" and after a few seconds the server disconnects for both. I also wanted to tell you that the only information exchanged between customers is the position of the two players. The error that appears in the consol is this:
Network destroy Instantiated GO: projectile (Clone)
UnityEngine.Debug: Log (Object)
Photon.Pun.PhotonNetwork: RemoveInstantiatedGO (GameObject, Boolean) (at Assets / Photon / PhotonUnityNetworking / Code / PhotonNetworkPart.cs: 712)
Photon.Pun.PhotonNetwork: LocalCleanupAnythingInstantiated (Boolean) (at Assets / Photon / PhotonUnityNetworking / Code / PhotonNetworkPart.cs: 265)
Photon.Pun.PhotonNetwork: LeftRoomCleanup () (at Assets / Photon / PhotonUnityNetworking / Code / PhotonNetworkPart.cs: 235)
Photon.Pun. <> C: <. Cctor> b__122_0 (ClientState, ClientState) (at Assets / Photon / PhotonUnityNetworking / Code / PhotonNetwork.cs: 990)
Photon.Realtime.LoadBalancingClient: set_State (ClientState) (at Assets / Photon / PhotonRealtime / Code / LoadBalancingClient.cs: 355)
Photon.Realtime.LoadBalancingClient: OnStatusChanged (StatusCode) (at Assets / Photon / PhotonRealtime / Code / LoadBalancingClient.cs: 2578)
ExitGames.Client.Photon. <> C__DisplayClass105_0: b__0 () (at C: /Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs: 907)
ExitGames.Client.Photon.EnetPeer: DispatchIncomingCommands () (at C: /Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs: 435)
ExitGames.Client.Photon.PhotonPeer: DispatchIncomingCommands () (at C: /Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs: 1548)
Photon.Pun.PhotonHandler: Dispatch () (at Assets / Photon / PhotonUnityNetworking / Code / PhotonHandler.cs: 193)
Photon.Pun.PhotonHandler: FixedUpdate () (at Assets / Photon / PhotonUnityNetworking / Code / PhotonHandler.cs: 127).

Comments

  • Nori_SC
    Nori_SC
    edited November 2019
    Options
    that's all you need
    if (Object.GetComponent<PhotonView>().IsMine)
                    {
                        PhotonNetwork.Destroy(Object);
                    }
                    else
                    {
                        Object.SetActive(false);
                        UnityEngine.Object.Destroy(Object,1f);
                    }
  • alessio
    Options
    maybe I was not clear, I do not want objects to be destroyed, the bullet, if it hits a gameobjet it only lowers its life, when life reaches 0 and players disconnect from the room, and this works. Now I try to repeat the question: because at the beginning of the game, when I connect and enter a room with another player, if I create an object with photon.instantiate (...), the master player no longer sees the other player and after a few seconds the players log off together at the same time? sorry for my bad english, i'm italian.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @alessio,

    Thank you for choosing Photon!

    if I create an object with photon.instantiate (...), the master player no longer sees the other player and after a few seconds the players log off together at the same time?


    Maybe you are calling PhotonNetwork.Instantiate too many times which causes the client to send too many events and the server ends up disconnecting both clients and closing the room.

    I suggest you implement OnDisconnected callback and log the cause.
    Also maybe implement OnEvent callback and check if you don't receive an event with code EventCode.ErrorInfo (251).
  • alessio
    Options
    I tried to implement the code you suggested, I wrote public override void OnDisconnected (Disconnect Cause causes)
    {
    Debug.Log (EventCode.ErrorInfo + "," + causes);
    }
    I also tested that it works, because when I disconnected the PC from the internet a warning appeared that told me: 251, ExceptionOnConnect; When I re-did the test where it gave me problems, I still got the same warning that I wrote to you in the first message 7-8 times, but I didn't see the suggestion I now implemented in OnDisconnected (); do you have any other ideas? I also wanted to tell you that I too had thought about the excessive sending of information, but I immediately discarded this hypothesis, because the only information I synchronize are the positions of the 2 players. Thanks for the support.
    last thing, I have just analyzed the graphs of traffic, msg / s for room, etc. and I saw that in the penultimate graph, that of traffic, I saw that I sent 500 kB while testing the game, so maybe you're right, but I don't understand what 500 kB of data sends; the position of the characters I set it to 10 times per second so you shouldn't have all these problems of heaviness!
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @alessio,

    This is what I meant by implementing OnDisconnected AND OnEvent:
    public class DebugDisconnects : MonoBehaviourPunCallbacks, IOnEventCallback
    {
        public override void OnDisconnected(DisconnectCause cause)
        {
            if (cause != DisconnectCause.ClientTimeout)
            {
                Debug.LogErrorFormat("OnDisconnected, cause = {0}", cause);
            }
        }
    
        public void OnEvent(EventData photonEvent)
        {
            if (photonEvent.Code == EventCode.ErrorInfo)
            {
                Debug.LogErrorFormat("ErrorInfo event: {0}", photonEvent.ToStringFull());
            }
        }
    }
    You are maybe calling PhotonNetwork.Instantiate or photonView.RPC with RpcTarget that ends w/ Buffered too many times.
    Or you are sending a huge message.

    I still got the same warning that I wrote to you in the first message 7-8 times
    This means you have at least 7-8 networked GameObjects that are being destroyed when the client does a clean up after leaving a room. The client is leaving the room due to an unexpected disconnect probably.
    the position of the characters I set it to 10 times per second
    How do you do that? manually? there is PhotonTransformView for this? you should attach it and add it to the list of observable components list in the PhotonView.
  • alessio
    Options
    sorry for the late reply but I was busy this week. I solved my problem, I saw that in the photon view component of the projectile, in the observed components field there were two fields but one was empty, I deleted it and now it works. however I also implemented the code that you suggested to me, but it didn't work for me, although I'm sure I set it well. last thing, in my last message I said that I had set the synchronization to 10 times per second, I was wrong, I set it to 30 times per second, in fact I set the item observe option as Unreliable on Change. Thanks for your help.