I have problem with ClientScene.RegisterPrefab
Hello, I have 2 scenes, in the first i have the network manager and network manager hud where specified the offline and online scenes, here i don't specified the spawnable prefabs.
In the second, i have a script where i specified the prefab to spawn. Here first to spawn i registered the prefab:
public override void OnStartClient()
{
base.OnStartClient();
foreach (GameObject obj in asteroidPrefabs)
{
ClientScene.RegisterPrefab(obj);
}
}
then if isServer i instanciate the prefab and then i spawn the prefab. The problem is on the client: I received the error on the client like (on the host the spawn is ok):
Failed to spawn server object, did you forget to add it to the NetworkManager? assetId=d8b3239a5790cd944ad93a8f8effa2b0 netId=6 UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
What is wrong? i following the manual: https://docs.unity3d.com/Manual/UNetSpawning.html
ps: i am trying to use ClientScene.RegisterPrefab and don't the registered spawnable object of Network Manager.
Here there is the project: https://drive.google.com/file/d/1e2VpyKc59Zid5lXjuVFL8HqBsJWCNAbF/view?usp=sharing
Thanks, bye
Answer by hexagonius · May 16, 2018 at 05:19 PM
This is a bug (1035798) and has been confirmed. OnStartClient is actually too late for the registration (I think just under localhost conditions or something like that). When you enable Developer Log mode on the NetworkManager, you will see the errors followed by the registration.
The correct way to do it when using HLAPI is calling it in Awake (they said the docu will reflect that in the future)
Your advice to put in Awake is so great! I use Mirror and it still applies! I have to put NetworkClient.RegisterPrefab(myPrefab)
to the Awake function as well.