'Unity networking. transform.setparent() not working on a clinet side
I am writing a simple multiplayer board game in Unity.
I have the following problem: transport.setparent() not working on a client side. When I launch a game as a server, everything is OK. When I connect to the server as a client transform.setParent() does nothing.
Here is my code:
public GameObject PlayerPrefab;
private GameObject player;
// Use this for initialization
void Start () {
if (!isLocalPlayer)
{
return;
}
Debug.Log("Spawning.");
CmdSpawn();
}
[Command]
void CmdSpawn()
{
player = Instantiate(PlayerPrefab);
NetworkServer.SpawnWithClientAuthority(player, connectionToClient);
player.transform.SetParent(GameObject.Find("BoardPanel").transform, false);
}
Solution 1:[1]
Use this to find the parent object:- Transform parentTransform = PhotonView.Find(parentid).gameObject.transform;
And then call the rpc to make the parent object on the client side like this:- this.GetComponent().RPC("RPC_DropObject", RpcTarget.AllBuffered, position, rotation, hasParent, parent.gameObject.GetComponent().ViewID);
Solution 2:[2]
I ended up trying an older version of got (11.8.2), which runs ES35 and that gives no problems at all. I'm guessing maybe the newer version of got which came out one month ago is causing some potential issues?
npm install [email protected]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nikunj Sethi |
| Solution 2 |
