Can’t destroy gameObject of the disconnected user

Hi there,

I’m really stuck with the problem when gameObjects of the disconnected users are not destroyed neither by auto clean nor by calling PhotonNetwork.DestroyPlayerObjects() in the OnPhotonPlayerDisconnected event (which just executes without any errors, but don’t really do the work).

I have photonView script attached for the player prefabs and when they disconnect the «owner» property is changed to «null, disconnected?», but the object itself just keeps appearing in the game. I even tried calling PhotonNetwork.Destroy(gameObject) when photonView.owner == null, but got the «Cannot call Destroy on the gameobject as we don't control it» error (naturally, as «null» is its owner >_<).

I tried searching for relevant issues in the web, but with no luck. I found somewhat close topic (viewtopic.php?f=17&t=1344 ), but the NetworkingPeer.cs script that was given there don’t work with the latest PUN library…

I just run out of ideas what can prevent gameObjects from being clean out, and will be grateful for any tips. Thanks!

Comments

  • Did you disable autocleanup?
    Which PUN version are you using?

    We can take a look. I would help if you could send a simple reproduction project or a clean description.
    This: "... the object itself just keeps appearing in the game" sounds like joining players still get the instantiate event? This should only happen when autocleanup is off.
    And these are events someone instantiated via PhotonNetwork.Instantiate(), right?
  • Thanks for the fast response :)

    Yes, I set PhotonNetwork.autoCleanUpPlayerObjects to false before implementing manual destroying (though, I tried it with auto clean up turned on — it was the same).

    I’m using latest PUN version 1.17.
    Tobias wrote:
    This: "... the object itself just keeps appearing in the game" sounds like joining players still get the instantiate event? This should only happen when autocleanup is off.
    Oh, sorry for my bad English. I meant that gameObject remains in the game after its owner disconnects, so other player can still see it.

    I’ve been trying to make a new reproduction project, but this simple part:
    [code2=csharp]using UnityEngine;
    using System.Collections;

    public class NetworkManager : Photon.MonoBehaviour {

    public Transform playerPrefab;

    void Start () {
    PhotonNetwork.ConnectUsingSettings("1.0");
    }

    private void OnConnectedToPhoton () {
    PhotonNetwork.JoinRoom("room");
    }

    private void OnJoinedRoom () {
    PhotonNetwork.Instantiate(playerPrefab.name, Vector3.zero, Quaternion.identity, 0);
    }

    }[/code2]
    fails to work with «OperationResponse 226: ReturnCode: -3 (Not authorized). Parameters: {}. State: Connected». I’ve checked AppID and other settings several times, but it just don’t want to authorize my test project >_< The main project however still authorizes just fine…
  • Ok, so I managed somehow to reproduce the problem in a new project (it was making a new scene and scripts inside the main project and then clearing all other stuff — then it allowed to authorize me… really weird, I would say). Here it is: https://docs.google.com/open?id=0BznuF1 ... 3RGX1IyaEU
    Would be very grateful if you could check it. The problem here is just as I described: player game objects won’t go away, no matter what I try…
  • Thanks for your repro case. It was easy to check out and really points to an issue.
    The problem is that the owner of the objects left but is still required in some points in code.

    Edit:
    I created an "experimental" version of PUN that fixes this specific problem in your repro case. It might still fail in some other cases but the idea should work and maybe just needs some polish.

    If you can help us out some more, download the attachment, try it and give feedback if this does it for you.
    Note: There is a lot of extra Debug.Log output. This will ruin performance and you are (of course) free to remove it. I just needed it to find out what's going on.
  • Ok, thank you for checking it. I will also try to fix it someway in the meanwhile, and will post here, if I’ll come up with anything.
  • See above: I edited my post.
    It was easier to get something working than I anticipated.
  • Yes, it’s working like a charm in both projects. Thank you very much! ;)
  • Was this fix incorporated into more recent versions of PUN? I'm having the same issue as the OP: I want to manually destroy the photonViews of a players who have left the game, which therefore have no owner.
  • I Have The Same Issue, the player prefab disconnected don't destroy and I controll both
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @ConceptFactory,

    This forum discussion is quite old and was created before PUN 2 which is what you are probably using.
    Could you clarify what you want to achieve?
    In this other comment, you complain that networked GameObjects are NOT being destroyed when the player leaves while here you you're saying the opposite.
    Maybe starting a new discussion where you explain the actual issue, PUN version, and what you want to achieve is better.