- Home /
NetworkViewID set to 0 at Start
I set up my Prefab with a NetworkView-Component. When I look at the Objects of the Prefab in the Unity-Editor, they all have a NetworkViewId and Type "Scene", however when I start the Game the NetworkViewIDs of all Objects of that Prefab become 0 and the Type changes to 'Allocated'. Naturally no State-Synchronisation or RPCs work. Nothing appears in the Console either.
Does anybody know what is happening here? I would like to be more detailed but I have no idea what is happening here. I have other Prefabs with a NetworkView, but everything is working fine with them. I don't even know if this is a bug or if I am doing something wrong.
So you aren't instantiating this prefab - it is just part of the scene?
Do you have a prefab or a prefab instance? Prefabs are off scene objects which can be instantiated into the scene at runtime. So i guess you have a scene object which has a NetworkView with a Scene-NetworkViewID, right? Do you have actually a problem with the ID?
A NetworkViewID consists of 3 integer values (private members a, b and c). The value you get back by ToString is probably either one of the ints are calculated from them. However you shouldn't bother about the actual value, just take the ID as an ID-object You don't have to care about how it works internally. You can compare ViewIDs and deter$$anonymous$$e it's owner, that should be enough.
@Bunny83: I put Instances of the Prefab into a Scene, and I actually have problems with the NetvorkViewID in the case of RPCs. An Example: I actually have two Objects with that Problem. One has the RPC-Function "pauseGameRPC" and the other does not. Now because both have the ID 0, the "pauseGameRPC"-Call is send to the one without that function.
Okay, found a Solution and posted an answer, thanks for your efforts.
Answer by NWegener · Jul 04, 2012 at 06:16 PM
Wow, I just found the Solution for the Problem: The Objects that I had that problem with were in the Scene, before I gave the Prefab a NetworkView-Component. So after I deleted the Objects and put new Instances of them in the Scene it worked for the new Instances.
Why that problem happened now and not before (as I had another Prefab where that worked fine), I do not know, but the important thing is I now know what to do if that happens again. Thanks to whydoidoit and bunny83 for trying to help.
I am glad to have found this post/answer!
I've been struggling with similar issues since long (see this discussion as an example). It is a new and very helpful information for me that this problem is related to manipulating a prefab after it has already been added to a scene!
I found out in my case that two things can work around the problem:
Delete and recreate the network views on any scene objects affected.
Even more elegant: Reverting the problematic network views of the scene objects affected to the prefab values (by right-clicking the network view in the inspector, then choosing "Revert to prefab").
At least in my case it helped fine! No more "unassigned 0 view IDs"!
You rock! I couldn't figure out why when i destroyed a "plant" prefab a different plant would be destroyed. I was about to start all the way over on the networking!.
I noticed saving and re-opening the scene twice, seems to fix it. (Not very scientific but it seemed to do a the trick).
Perhaps it is an editor error?
Answer by nevaran · Oct 26, 2013 at 12:03 PM
The thing is that every object in the scene with the network view component attached to it has a view id of 0, which means the owner is the server. Any other id is the client.
But again, this is from what I experienced with the network and haven't read it from anywhere. Allthou I have recently figured that out, it seems to work for what the problem ive had with my pick up system in the multiplayer game im making.
To set a view id owner, you can see the box spawn example at the docs: http://docs.unity3d.com/Documentation/ScriptReference/Network.AllocateViewID.html
From all ive researched though, view id 0 is always the server, and the others are always the clients(have not tested with negative ids as -1, -2, ect.)
Hope this was useful. Cheers
-Nevaran
Answer by JosephGrainger · Aug 06, 2015 at 03:17 PM
I have found if you have a prefab in multiple scenes, and you apply a new child object which holds a NetworkView to the prefab it will automatically receive the ID of 0 (Using Unity 5.1.2f).
I have found a simple solution to this to be to re-import the project which re-allocates objects with new NetworkView IDs. I have also tried re-importing individual scenes, but on occasion the issue has remained.
Your answer