lidgren / lidgren-network-gen3

Lidgren Network Library
https://groups.google.com/forum/#!forum/lidgren-network-gen3
MIT License
1.19k stars 331 forks source link

Incompatibility with Unity 2018.2+ #107

Open Reelix opened 5 years ago

Reelix commented 5 years ago

PlatformConstrained.cs -> Line 37 -> 'Network.player' is obsolete: 'The legacy networking system has been removed in Unity 2018.2. Use Unity Multiplayer and NetworkIdentity instead.'

This has larger ramifications than just this one file, and I noticed that it was missing from the Issue Tracker.

NFMynster commented 5 years ago

Isn't that because you aren't using the right namespace? It tries to get the UNET namespace @Reelix

chrisnobrega commented 5 years ago

@Jan1902 It is actually being called within Lidgren itself. You can find it at line 37 in PlatformConstrained.cs https://github.com/lidgren/lidgren-network-gen3/blob/master/Lidgren.Network/Platform/PlatformConstrained.cs

Jan1902 commented 5 years ago

@chrisnobrega Oh, neat to know, I wasn't aware of that :)

paul-hansen commented 5 years ago

I replaced these lines: https://github.com/lidgren/lidgren-network-gen3/blob/d3458db59c082e8541f07cd738523996753e2f7c/Lidgren.Network/Platform/PlatformConstrained.cs#L30-L43 with:

#if UNITY_ANDROID || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_IOS || UNITY
            try
            {
                string localIP;
                using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
                {
                    socket.Connect("8.8.8.8", 65530);
                    IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
                    localIP = endPoint.Address.ToString();
                }
                return IPAddress.Parse(localIP);
            }
            catch // Catch Access Denied errors
            {
                return null;
            }
#endif

Source: https://stackoverflow.com/a/27376368/5399098

This seems to work for me at the moment. Hope this helps someone else.

You can also just have it return null, and most everything will still work, I think the main thing it would break is port forwarding using UPnP.