Disable navmeshagent on clients to allow Photon Transform View (Not working)

I spawn a unit with:
newUnit = PhotonNetwork.Instantiate(unitPrefabString, spawnPoint, Quaternion.identity, 0);
This has a Navmeshagent as one of its components, and it's navigating across my map. I want to sync this from the master who runs the navmeshagent to my client (it's a 1 vs 1 game), so I want to disable the navmeshagent, using this in a script on the unit:
void OnPhotonInstantiate(PhotonMessageInfo info) {
  print(agent.enabled); // Shows true
  // Got instantiated over the network, remove navmeshagent
  agent.enabled = false;
  print(agent.enabled);  // Shows false, but it's still enabled in inspector
}
The weird thing is that even if the last print says "False", it's still enabled and ticked in in the inspector. I can't figure out why. Agent is correctly assigned to the navmeshagent component.

Anyhow, even if I manually disable the navmeshagent on the client, it still doesn't update the position, that I try to sync with a Photon Transform View which is setup like the image below.

Did I miss anything in the setup? I'm not sure if I should observe Photon Transform View or not, but it's not working in any case.

I'm grateful for any ideas here!


Comments

  • Sorry, I had another script that was enabling the agent after this was run. Sorry, it's working now. DELETE? :)
  • Hi @nicmar,

    good to see, that you have already found a solution. I just want to give you another hint, how you can handle such a scenario. agent.enabled = photonView.isMine; in either the OnPhotonInstantiate callback or the Awake / Start function basically does the same. This would be also a way to handle things if the current MasterClient leaves the game and / or a new one is selected and you would have to do something in this case (not sure if this would apply to the scenario you currently have). In this case you would have to insert the above code in the OnMasterClientSwitched callback.
  • Thanks, smart tip! :)
Sign In or Register to comment.