"One of the requirements to be able to spawn a network prefab instance is that it must be registered with the NetworkManager via the “Network Prefabs” property list. The two steps to registering a network prefab with NetworkManager:
Create a network prefab by creating a prefab with a NetworkObject component attached to the root GameObject
Add your network prefab to the Network Prefabs list property of the NetworkManager.
"
You’ll find the list of NetworkPrefab’s in the NetworkManager inspector. Does this help?
Well, it’s just a game object in the scene with a NetworkObject component attached to it (so, I’m not spawning it). I thought it was fine, shouldn’t I do this?
Just right now I’m experiencing this issue all the time. It points to a ClientRpc called from the host at the “OnClientConnected” callback.
When I start the game as a host, it throws this error.
This script (Networkbehaviour) is attached to a prefab that is in the “NetworkManager” script => NetworkPrefabs list.
(1) Could it be that this is not the list the error is talking about?
(2) Or maybe a problem with the Netcode version (1.0.2) (I don’t know how to update it: there’s no update showing at the Package Manager (I’m using Unity 2021.3.12f1))
Indeed, it’s exactly what you were talking about. Apparently, OnClientConnected is too early for an Rpc call because the client’s Network is not spawned yet, and it throws exceptions.
I need to send the clientId, the clientGuid, and some other parameters, but that should be fairly straightforward:
On the OnNetworkSpawn callback, I can send a [ServerRpc (RequireOwnership= false)] and then get all the needed parameters.
The client ID could be easily gotten with:
var clientId = serverRpcParams.Receive.SenderClientId;