Hello there,
I’m trying to use the ConnectionApproval feature to choose which prefab to spawn for my client as a PlayerObject.
In the documentation (https://docs-multiplayer.unity3d.com/docs/getting-started/connection-approval), it is said that the ConnectionApprovalCallback can take as parameter the hash of the prefab to use as the player object.
Here is the example code of ApprovalCheck in the documentation:
private void ApprovalCheck(byte[] connectionData, ulong clientId, MLAPI.NetworkManager.ConnectionApprovedDelegate callback)
{
//Your logic here
bool approve = true;
bool createPlayerObject = true;
// The prefab hash. Use null to use the default player prefab
// If using this hash, replace "MyPrefabHashGenerator" with the name of a prefab added to the NetworkPrefabs field of your NetworkManager object in the scene
ulong? prefabHash = NetworkSpawnManager.GetPrefabHashFromGenerator("MyPrefabHashGenerator");
//If approve is true, the connection gets added. If it's false. The client gets disconnected
callback(createPlayerObject, prefabHash, approve, positionToSpawnAt, rotationToSpawnWith);
}
I’m using Netcode for GameObjects 1.0.0-pre.6, and the problem is, in that version, NetworkSpawnManager.GetPrefabHashFromGenerator
doesn’t exist anymore. It seems to me that the callback is waiting an uint corresponding to the GlobalObjectIdHash of the NetworkObject and I have no idea how to access it (everything using it seems to be internal).
I know there is a workaround, I can call the callback with createPlayerObject set to false and manage the player object spawn manually, but it’s not as clean as make the framework create it for us.