Unity network manager assign playerprefab at runtime
I am dynamically creating my player gameobject at runtime, and I need to set this player gameobject as the playerprefab object of my NetworkManager. What I am doing now is I am creating a copy of my player object and adding a NetworkIdentity component to the copy, then I assign this copy to the PlayerPrefab of the NetworkManager.
In the editor, I see that it gets correctly assigned, but when I click Start Host, I still get the error message "The PlayerPrefab is empty on the NetworkManager. Please setup a PlayerPrefab object."
Any ideas?
Here is the code I use to set the PrefabPlayer of my NetworkManager. (NetworkManagerCustom is just a custom script that inherits from NetworkManager, with some extra functions).
GameObject nm = GameObject.Find("NetworkManager");
NetworkManagerCustom nmc = nm.GetComponent<NetworkManagerCustom>() as NetworkManagerCustom;
GameObject copy = GameObject.Instantiate(core);
NetworkIdentity ni = copy.AddComponent<NetworkIdentity>();
ni.localPlayerAuthority = true;
nmc.playerPrefab = copy;
Comment