I’ve been working on a simple game with basic 2d movement and networking for about a week now. I got NGO working and I added Relay, both with a good number of troubles, but I’m at a point where it works. However, whenever I start a host, there’s two errors which don’t really make any sense to me. These two errors seem to be directly responsible for two memory leaks as well. It’s still perfectly playable, and after the first two errors it tries again successfully, but I want to fix this issue before I move on. I’ve tried many different things and none of them have worked. For reference, here’s the code along with the full four errors:
using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.Netcode;
using Unity.Netcode.Transports.UNET;
using Unity.Netcode.Transports.UTP;
using Unity.Networking.Transport.Relay;
using Unity.Services.Authentication;
using Unity.Services.Core;
using Unity.Services.Relay;
using Unity.Services.Relay.Models;
using UnityEngine;
using UnityEngine.UI;
public class RelayTest : MonoBehaviour
{
[SerializeField] private Button hostButton;
[SerializeField] private Button joinButton;
[SerializeField] private TMP_InputField codeJoin;
private void Awake()
{
hostButton.onClick.AddListener(() =>
{
CreateRelay();
});
joinButton.onClick.AddListener(() =>
{
JoinRelay(codeJoin.text);
});
}
private async void Start()
{
await UnityServices.InitializeAsync();
AuthenticationService.Instance.SignedIn += () =>
{
Debug.Log("Signed in: " + AuthenticationService.Instance.PlayerId);
};
await AuthenticationService.Instance.SignInAnonymouslyAsync();
}
private async void CreateRelay()
{
try
{
Allocation allocation = await RelayService.Instance.CreateAllocationAsync(9);
string joinCode = await RelayService.Instance.GetJoinCodeAsync(allocation.AllocationId);
Debug.Log(joinCode);
RelayServerData relayServerData = new RelayServerData(allocation, "dtls");
NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(relayServerData);
NetworkManager.Singleton.StartHost();
} catch (RelayServiceException err) {
Debug.Log(err);
}
}
private async void JoinRelay(string joinCode)
{
try
{
Debug.Log("Joining relay with: " + joinCode);
JoinAllocation joinAllocation = await RelayService.Instance.JoinAllocationAsync(joinCode);
RelayServerData relayServerData = new RelayServerData(joinAllocation, "dtls");
NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(relayServerData);
NetworkManager.Singleton.StartClient();
} catch (RelayServiceException err) {
Debug.Log(err);
}
}
}
Error #1: You must call SetRelayServerData() at least once before calling StartRelayServer.
Error #2: Server is shutting down due to network transport start failure of UnityTransport!
Memory Leak 1
A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Networking.Transport.NetworkSettings:.ctor(Allocator) (at Library\PackageCache\com.unity.transport@1.3.4\Runtime\NetworkSettings.cs:63)
Unity.Netcode.Transports.UTP.UnityTransport:Initialize(NetworkManager) (at Library\PackageCache\com.unity.netcode.gameobjects@1.4.0\Runtime\Transports\UTP\UnityTransport.cs:1190)
Unity.Netcode.NetworkManager:Initialize(Boolean) (at Library\PackageCache\com.unity.netcode.gameobjects@1.4.0\Runtime\Core\NetworkManager.cs:833)
Unity.Netcode.NetworkManager:StartHost() (at Library\PackageCache\com.unity.netcode.gameobjects@1.4.0\Runtime\Core\NetworkManager.cs:953)
<>c:b__2_0() (at Assets\Scripts\NetManUI.cs:16)
UnityEngine.Events.InvokableCall:Invoke()
UnityEngine.Events.UnityEvent:Invoke()
UnityEngine.UI.Button: Press() (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\UI\Core\Button.cs:70)
UnityEngine.UI.Button:OnPointerClick(PointerEventData) (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\UI\Core\Button.cs:114)
UnityEngine.EventSystems.ExecuteEvents:Execute(IPointerClickHandler, BaseEventData) (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\ExecuteEvents.cs:57)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1) (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\ExecuteEvents.cs:272)
UnityEngine.EventSystems.StandaloneInputModule:ReleaseMouse(PointerEventData, GameObject) (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:190)
UnityEngine.EventSystems.StandaloneInputModule: ProcessMousePress(MouseButtonEventData) (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:640)
UnityEngine.EventSystems.StandaloneInputModule: ProcessMouseEvent(Int32) (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:546)
UnityEngine.EventSystems.StandaloneInputModule: ProcessMouseEvent() (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:526)
UnityEngine.EventSystems.StandaloneInputModule: Process() (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:280)
UnityEngine.EventSystems.EventSystem:Update() (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\EventSystem.cs:514)
Memory Leak 2
A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeList1:.ctor(AllocatorHandle) (at Library\PackageCache\com.unity.collections@1.4.0\Unity.Collections\NativeList.cs:106) Unity.Networking.Transport.NetworkSettings:.ctor(Allocator) (at Library\PackageCache\com.unity.transport@1.3.4\Runtime\NetworkSettings.cs:62) Unity.Netcode.Transports.UTP.UnityTransport:Initialize(NetworkManager) (at Library\PackageCache\com.unity.netcode.gameobjects@1.4.0\Runtime\Transports\UTP\UnityTransport.cs:1190) Unity.Netcode.NetworkManager:Initialize(Boolean) (at Library\PackageCache\com.unity.netcode.gameobjects@1.4.0\Runtime\Core\NetworkManager.cs:833) Unity.Netcode.NetworkManager:StartHost() (at Library\PackageCache\com.unity.netcode.gameobjects@1.4.0\Runtime\Core\NetworkManager.cs:953) <>c:<Awake>b__2_0() (at Assets\Scripts\NetManUI.cs:16) UnityEngine.Events.InvokableCall:Invoke() UnityEngine.Events.UnityEvent:Invoke() UnityEngine.UI.Button: Press() (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\UI\Core\Button.cs:70) UnityEngine.UI.Button:OnPointerClick(PointerEventData) (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\UI\Core\Button.cs:114) UnityEngine.EventSystems.ExecuteEvents:Execute(IPointerClickHandler, BaseEventData) (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\ExecuteEvents.cs:57) UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction
1) (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\ExecuteEvents.cs:272)
UnityEngine.EventSystems.StandaloneInputModule:ReleaseMouse(PointerEventData, GameObject) (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:190)
UnityEngine.EventSystems.StandaloneInputModule: ProcessMousePress(MouseButtonEventData) (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:640)
UnityEngine.EventSystems.StandaloneInputModule: ProcessMouseEvent(Int32) (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:546)
UnityEngine.EventSystems.StandaloneInputModule: ProcessMouseEvent() (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:526)
UnityEngine.EventSystems.StandaloneInputModule: Process() (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:280)
UnityEngine.EventSystems.EventSystem:Update() (at Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\EventSystem.cs:514)
I’m on editor 2021.3.24f1, and if it helps, here are all of my installed packages:
I’ve tried a handful of fixes already. I tried downgrading NGO to 1.3.4, the recommended version, but the same issue remained, so I returned to 1.4.0. I also went to the Unity Relay docs and straight up copied their code on integration with NGO to see if it worked, and it resulted in the same errors. I restarted my computer. I hope somebody here has any insights on what the issue could be.