- Home /
Owner on NetworkViewID not consistent when sent over RPC
Hello,
I am trying to instantiate object in all the connected players using RPC instead of Network.Instantiate (because I need to send additional parameters).
The player that initiate the instantiation allocates a NetworkViewID and calls a RPC to all players with this view ID as parameter. A GameObject is instantiated in this RPC and its NetworkView's view ID is overrided with the value received as a parameter. But I have a strange problem : it seems that the owner of this view ID is no longer the player that has allocated it in all the player.
Let's say that I have a server (p0) and two clients (p1 & p2). p1 allocates the view ID and calls the RPC on everybody :
Owner on p0 : p1 (OK)
Owner on p1 : p1 (OK)
Owner on p2 : p0 (ERROR)
This owner inconsistency creates problem when I call RPC from the new NetworkView. Depending from which player I call them, not everybody receive the RPC call.
I have made this little class to illustrate the problem :
[RequireComponent(typeof(NetworkView))]
public class TestViewID : MonoBehaviour
{
[RPC]
void Test(NetworkViewID viewID)
{
Debug.Log("player: " + Network.player.ToString()
+ " viewID: " + viewID.ToString()
+ " owner: " + viewID.owner.ToString());
}
void OnGUI ()
{
if (GUILayout.Button("Test"))
{
networkView.RPC("Test", RPCMode.All, Network.AllocateViewID());
}
}
}
When I click on Test on player 1 I get the previous result but you can see the the ViewID's "id" is the same on all players :
player: 0 viewID: AllocatedID: 50 owner: 1
player: 1 viewID: AllocatedID: 50 owner: 1
player: 2 viewID: AllocatedID: 50 owner: 0
Is it a normal behaviour or a bug ? I am using RPCs and AllocalteViewID correctly ? How can I allocate a view ID on (potentially) a client, and send it over RPC while keeping the same owner ?
I am using Unity 3.5.7 but there is the same behaviour on unity 4.0.
Answer by azix · Mar 25, 2013 at 01:42 PM
Well, it seems to be a known problem : http://forum.unity3d.com/threads/51312-networkView-owner-issue?highlight=networkview%20owner
purely FWIW ...
http://answers.unity3d.com/questions/326626/games-with-multiple-maps.html
many people just NEVER USE the "send to all" mode of the RPC call in Unity. Arguably, it's basically 'crazy" and it's best to never use it.
Stick to normal, conventional, 40-years-proven "hub and spoke" networking.
I never use the "crazy" version of the RPC call, because it's, well, crazy :) So I didn't even know the problem you describe.
So just a thought.
Your answer
Follow this Question
Related Questions
Send RPC to owning NetworkPlayer of networkView 1 Answer
Does the position change need state synchronization? 2 Answers
Problem with Playmaker Send Remote Event 1 Answer
RPC with Network View 0 Answers
get return on networkView.RPC 1 Answer