NetworkConfig.ConnectionData causes NullRefException
I am using simple approval:
using System.Text;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;
public class NetworkPassword : MonoBehaviour
{
[SerializeField] private InputField PasswordInputField;
[SerializeField] private Button HostButton;
[SerializeField] private Button ClientButton;
[SerializeField] private Button LeaveButton;
private void Start()
{
HostButton.onClick.AddListener(Host);
ClientButton.onClick.AddListener(Client);
LeaveButton.onClick.AddListener(Leave);
}
public void Host()
{
NetworkManager.Singleton.ConnectionApprovalCallback += ApprovalCheck;
NetworkManager.Singleton.StartHost();
}
public void Client()
{
NetworkManager.Singleton.NetworkConfig.ConnectionData = Encoding.ASCII.GetBytes(PasswordInputField.text);
NetworkManager.Singleton.StartClient();
}
public void Leave()
{
NetworkManager.Singleton.Shutdown();
}
private void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.ConnectionApprovedDelegate callback)
{
string password = Encoding.ASCII.GetString(connectionData);
bool approveConnection = string.Equals(password,PasswordInputField.text);
callback(true, null, approveConnection, null, null);
}
}
If the client enters the correct host password, then it connects correctly, even if the password is blank. If it enters a wrong password or sends an empty one, and the host has a password, then an exception occurs:
NullReferenceException: Object reference not set to an instance of an object Unity.Netcode.NetworkManager.OnNetworkEarlyUpdate () (at Library/PackageCache/[email protected]/Runtime/Core/NetworkManager.cs:1144) Unity.Netcode.NetworkManager.NetworkUpdate (Unity.Netcode.NetworkUpdateStage updateStage) (at Library/PackageCache/[email protected]/Runtime/Core/NetworkManager.cs:1115) Unity.Netcode.NetworkUpdateLoop.RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage updateStage) (at Library/PackageCache/[email protected]/Runtime/Core/NetworkUpdateLoop.cs:149) Unity.Netcode.NetworkUpdateLoop+NetworkEarlyUpdate+<>c.<CreateLoopSystem>b__0_0 () (at Library/PackageCache/[email protected]/Runtime/Core/NetworkUpdateLoop.cs:172)
In the build, this is not noticeable and it seems that everything is correct.
Sorry for the late response. Were you able to fix this (if so how?) or is it still an issue?
Added to backlog MTT_3232
@Falkonio can you please confirm if you're still seeing this in the latest version of the SDK?
Assigning to myself to verify and close.
Closing due to lack of activity or response from the reporting user.