Network.instantiate and Netork.Destory.

I am having issues with Network.Destroy. When I try to Destroy a Network instantiated game object it crashes Unity Editor. It also crashes the Webplayer if I build it.

Here is what I do.

var instance = Network.Instantiate(prim, pos, rot, 0);
instance.networkView.RPC(“SetOwnerInformation”, RPCMode.All, LevelData.GetInstance().GetName());

Then I do this to delete all objects of this type

var prims : GameObject[ ];
prims = GameObject.FindGameObjectsWithTag(“PrimitivePrefab”);

for(prim in prims)
{
print("ShapeL: Netork View ID: " + prim.networkView.viewID);
Network.RemoveRPCs(prim.networkView.viewID);
Network.Destroy(prim.networkView.viewID);
}

The networkView.viewID match up. I have verified that. I do NOT get any more information from the Crash Report.

Any ideas?

Do you actually declare the variable prim?

ex:var prim:GameObject

If not do so.

Or instead of for(prim in prims)

try for(GameObject in prims)

Pretty sure that last line of code there just won’t work. I know that UnityScript does magic, but how are you supposed to refer to the GameObject it gives you?

Also, while it could be different in UnityScript, wouldn’t it be “foreach” instead of “for”?

In Unityscript, there is no foreach.

You are right… I meant this:

for(var prim:GameObject in prims)

Thank you for your suggestions. Unfortunately declaring “prim” as a GameObject does not fix this issue.

What surprises me is that this crashes the Unity Editor.

I have verified that the Network.viewIDs are correct.

Any help would be greatly appreciated

Are you sure it is that script causing the crash? If that segment of code is apart of a larger code file, try commenting out certain chunks and trying again until the crash stops. Once you find the code chunk, start commenting out individual lines and trying to get rid of the crash.

I have narrowed it down to this one line of code that crashes the Editor.

But… I belive this is a side effect of the Network.Instantiate not working correctly. I’m currently trying to figure out why my objects are not being created correctly.

Try Network.Destroy(prim);

If you’re already enumerating a list of GameObjects why not use the overload that takes a GameObject instead of a NetworkViewID?

Ok, looks like the destroy may not be the problem.

When a primitive is created using Network.Instantiate on the remote client I get this error on the local client.

View ID AllocatedID: 15352 not found during lookup. Strange behaviour may occur
(Filename: C:/BuildAgent/work/b0bcff80449a48aa/Runtime/Network/NetworkManager.cpp Line: 1676)
Could’t invoke RPC function ‘SetOwnerInformation’ because the networkView ‘AllocatedID: 15352’ doesn’t exist

I see this same issue from the Editor too.

I’m not sure why I’m getting this message. I have two Avatars in the world at the same time and they are working correctly.