-
Notifications
You must be signed in to change notification settings - Fork 465
Description
Hi
I have a custom player prefabs where each client sends a payload of the prefab he had chosen to play with, the server has Connection Approval enabled and from there I successfully decode the data and find the appropriate prefab that should be attached to the player
The problem I am facing comes short after callback finishes execution
Specifically, issue is on this line as PlayerPrefab is null for some reason
The prefab has NetworkObject attached to it and its in Network Prefabs List
See my approval callback and how I grab the PlayerPrefabHash from my prefab
private void ConnectionApproval(NetworkManager.ConnectionApprovalRequest request, NetworkManager.ConnectionApprovalResponse response)
{
response.Approved = true;
response.CreatePlayerObject = true;
int clientOperatorType;
try
{
clientOperatorType = System.BitConverter.ToInt32(request.Payload);
}
catch (System.Exception)
{
response.Approved = false;
response.Reason = "Could not resolve OperatorType parameter.";
return;
}
foreach (var data in OperatorPrefabsData.operatorPrefabPairs)
{
if ((int)data.operatorType == clientOperatorType)
{
NetworkObject netObject = data.prefab.GetComponent<NetworkObject>();
response.PlayerPrefabHash = netObject.PrefabIdHash;
Debug.Log(response.PlayerPrefabHash);
break;
}
}
if (response.PlayerPrefabHash == 0)
{
response.Approved = false;
response.Reason = $"Could not find OperatorType {clientOperatorType}";
}
else
{
SetClientOperatorType(request.ClientNetworkId, clientOperatorType);
}
if (!response.Approved)
{
Debug.LogError($"Connection request from {request.ClientNetworkId} denied: {response.Reason}");
}
}In the console I can see that response.PlayerPrefabHash is populated properly but the package fails to set the playerprefab after all.
Please advice what can be the issue in here?
Tested on both 1.8.1 and 1.11.0