Missing a valid InstantiationId on view when manually instantiated

Options
I am making a procedural dungeon in Unity and I am using PUN. I am trying to spawn items that have a photon view in the scene. The walls and everything are done by seed its just interactable items. You can imagine that I dont want to have links to my resource folder for every items since I have A LOT of items. So I am trying the manual instantiation as described at the bottom of this page https://doc.photonengine.com/zh-tw/pun/current/manuals-and-demos/instantiation . The problem is when I try to destroy an item I get this error:

Failed to 'network-remove' GameObject because it is missing a valid InstantiationId on view: View (0)106 on MoneyPileBig(Clone) (scene). Not Destroying GameObject or PhotonViews!
UnityEngine.Debug:LogError(Object)
NetworkingPeer:RemoveInstantiatedGO(GameObject, Boolean) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3336)
PhotonNetwork:Destroy(GameObject) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2744)
NetworkDestroyer:RPCNetworkDestroy() (at Assets/Scripts/Photon/NetworkDestroyer.cs:17)
System.Reflection.MethodBase:Invoke(Object, Object[])
NetworkingPeer:ExecuteRpc(Hashtable, PhotonPlayer) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2891)
NetworkingPeer:OnEvent(EventData) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2484)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:157)

Here is my code:

private List toPhotonInstantiate = new List();

private void CustomInstantiate(GameObject _prefab, Vector2 _position, Quaternion _rotation, Transform _parent)
{
if (_prefab.GetComponent() != null)
{
Debug.Log("instantiate" + 1);
toPhotonInstantiate.Add(new PhotonInstantiatingInfo(_prefab, _position, _rotation, _parent));
}
else
{
Debug.Log("instantiate" + 2);
Instantiate(_prefab, _position, _rotation, _parent);
}
}

private class PhotonInstantiatingInfo
{
public GameObject Prefab { get; private set; }
public Transform Parent { get; private set; }
public Vector2 Position { get; private set; }
public Quaternion Rotation { get; private set; }

public PhotonInstantiatingInfo(GameObject _prefab, Vector2 _position, Quaternion _rotation, Transform _parent)
{
Prefab = _prefab;
Parent = _parent;
Position = _position;
Rotation = _rotation;
}
}

private void InstantiatePhotonObjects()
{
if (!PhotonNetwork.isMasterClient) { return; }
for (int i = 0; i < toPhotonInstantiate.Count; i++)
{
int newViewId = PhotonNetwork.AllocateSceneViewID();
myPhotonView.RPC("RPCPhotonInstantiate", PhotonTargets.AllBufferedViaServer, i, newViewId);
}
}

[PunRPC]
private void RPCPhotonInstantiate(int _index, int _viewId)
{
PhotonInstantiatingInfo instantiationInfo = toPhotonInstantiate[_index];
GameObject newPlayer = Instantiate(instantiationInfo.Prefab, instantiationInfo.Position, instantiationInfo.Rotation) as GameObject;
PhotonView[] nViews = newPlayer.GetComponentsInChildren();
nViews[0].viewID = _viewId;
}

How can I solve this?

Comments

  • Gangafintie
    edited November 2017
    Options
    It doesnt show my list type for some reason but it is the right type!
  • [Deleted User]
    edited November 2017
    Options
    Hi @Gangafintie,

    I have tried this scenario on my own and can at least confirm that Manual Instantiation isn't working when using in combination with PhotonNetwork.Destroy(...). Since I got the same error message like you, I guess you are using PhotonNetwork.Destroy(...), too. This however isn't a bug at all.

    When using Manual Instantiation we want you to keep an eye on those objects yourself. Another reason is the PhotonNetwork.Instantiation(...) call itself and how it is handled on the server. So in order to remove manually instantiated objects, you have to use something like 'Manual Destroy' (to stay close to the original name). Therefore you have to do basically the same as for Manual Instantiation, but you obviously have to use GameObject.Destroy instead of GameObject.Instantiate this time. Sorry that this is unclear and not mentioned in the docs.

    Please let me know if you have further questions about this topic.
  • Thanks I found this out myself already :)!