- Home /
Network Instantiate PlayerPrefab Problem
I have a problem with instantiating my Prefabs on different Clients.
When the first client is connected to server he can move the way he should. But when the second is connected to server there are some problems:
On the first client appears a copy of the first player so I do move 2 Characters (one of them collides with the player of client 2 and the other not. The second player moves the correct way like on the second Client.
Does anyone know how to solve this problem?
Here is my Code:
using uLink;
using UnityEngine;
public class InstantiateScript : uLink.MonoBehaviour
{
public GameObject PlayerPrefab;
private GameObject playerAvatar;
public static GUIText lifePointsAvatar;
public static bool loggedIn;
private int level;
void OnLevelWasLoaded(int level)
{
if(level==1)
{
networkView.RPC("Instantiate", uLink.RPCMode.AllBuffered, "test");
}
}
public void uLink_OnPlayerDisconnected(uLink.NetworkPlayer player)
{
// Removing player from network and scene
uLink.Network.RemoveRPCs(player, 0);
uLink.Network.DestroyPlayerObjects(player);
}
[RPC]
void Instantiate(string test)
{
playerAvatar = uLink.Network.Instantiate(PlayerPrefab, transform.position, transform.rotation, 0);
Debug.Log("Network aware game object is now created on client" + playerAvatar);
loggedIn = true;
}
}
Answer by Seizure · Sep 06, 2013 at 04:12 PM
For almost every script I create that will be on network.instantiate i use
if (!networkView.isMine)
{
this.enabled = false;
}
Doesn't work for me. I think the problem could be RPC$$anonymous$$ode.AllBuffered so that the first player gets a copy of himself. But I still can't solve it.
Answer by Amyr · Nov 21, 2014 at 07:48 PM
You don't need to RPC a Network.Instantiate. When you use Network.Instantiate you are already doing a buffered RPC. So, if you call it on RPC you are kind of doing the same thing twice, thus two instances. I had a similar problem myself.
Your answer
Follow this Question
Related Questions
Send Prefab by RPC? 1 Answer
Show prefab's children over network 1 Answer
Problem with Camera instantiating 1 Answer
Buffered RPCs Only Sent To One New Client 0 Answers
Instantiate: Create Connection 1 Answer