Client updating prefab on inspector, but spawning the old prefab

by Shuvro Sarkar   Last Updated February 27, 2019 02:13 AM

I am making an AR (ArCore Cloud anchor) multiplayer(UNet) game with unity. In the game, a player can select an object with ui buttons and touch on screen to place the object. This is how I have set up the project.

UiManager(NotNetworked): contains a listener for button click. Inside the listener method only one line of code to change the object prefab.

void SelectObject()
   GameObject.Find("LocalPlayer").GetComponent<Player>().objectToPlace = objectToSpawn;

Player(Networked): Contains a cmdSpawn method to instantate the object which is called by Input Manager(Not Networked)

public GameObject objectToPlace;

public override void OnStartLocalPlayer()
  base.OnStartLocalPlayer(); = "LocalPlayer";

 public void CmdPlaceObject(Vector3 pos, Quaternion rotation)

  var myObj = Instantiate(objectToPlace, pos, rotation);
  // NetworkServer.SpawnWithClientAuthority(myObj,gameObject);

Now the problem is that, when i try to change the objectToPlace gameobject from client, it shows the change in inspector, but it spawns the old object(Not the selected one)Screen Shot here:

I have looked into forums for answers, tried a few(ClientRPC, AssinclientAuthority,SyncVar) Solutions. But I have been unable to map these with my problem.

Related Questions

Same playerControllerId Unity UNET

Updated September 04, 2016 08:05 AM

How to stop a host from the client script?

Updated October 24, 2016 09:05 AM