NetworkingPeer.LocalCleanupAnythingInstantiated C# (CSharp) Method

LocalCleanupAnythingInstantiated() protected method

Cleans up anything that was instantiated in-game (not loaded with the scene).
protected LocalCleanupAnythingInstantiated ( bool destroyInstantiatedGameObjects ) : void
destroyInstantiatedGameObjects bool
return void
    protected internal void LocalCleanupAnythingInstantiated(bool destroyInstantiatedGameObjects)
    {
        if (tempInstantiationData.Count > 0)
        {
            Debug.LogWarning("It seems some instantiation is not completed, as instantiation data is used. You should make sure instantiations are paused when calling this method. Cleaning now, despite this.");
        }

        // Destroy GO's (if we should)
        if (destroyInstantiatedGameObjects)
        {
            // Fill list with Instantiated objects
            HashSet<GameObject> instantiatedGos = new HashSet<GameObject>();
            foreach (PhotonView view in this.photonViewList.Values)
            {
                if (view.isRuntimeInstantiated)
                {
                    instantiatedGos.Add(view.gameObject); // HashSet keeps each object only once
                }
            }

            foreach (GameObject go in instantiatedGos)
            {
                this.RemoveInstantiatedGO(go, true);
            }
        }

        // photonViewList is cleared of anything instantiated (so scene items are left inside)
        // any other lists can be
        this.tempInstantiationData.Clear(); // should be empty but to be safe we clear (no new list needed)
        PhotonNetwork.lastUsedViewSubId = 0;
        PhotonNetwork.lastUsedViewSubIdStatic = 0;
    }
NetworkingPeer