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.