Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Solved] Where is BasicNetworkDriver?

Discussion in 'Multiplayer' started by zhuchun, Apr 17, 2019.

  1. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Hi, I have an existing project and I want to upgrade multiplayer to the latest since I'm moving to Unity 2019. After copied files to the package folder, the compiler says "The type or namespace name 'BasicNetworkDriver<>' does not exist in the namespace 'Unity.Networking.Transport'". I can't find any update in the manual as well, please help.

    networkDriver.png
     
  2. ARLS

    ARLS

    Joined:
    Jul 19, 2018
    Posts:
    1
    zhuchun and gooodpgr like this.
  3. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Thank you @ARLS . NetworkPipeline is a cool feature. Here is a checklist for people who need to upgrade their projects from previous version.

    1. Upgrade to Unity 2019, follow the instruction and copy files.

    2. UdpNetworkDriver is a class now, so just delete
    Code (CSharp):
    1. using UdpNetworkDriver = Unity.Networking.Transport.BasicNetworkDriver<Unity.Networking.Transport.IPv4UDPSocket>;
    3. Use NetworkEndpoint instead of IPEndPoint(IIRC;)) where server/client starts.

    4. Use UdpNetworkDriver.CreatePipeline() to instantiate a pipeline, it comes with useful things like reliable packet and network simulate(latency/packet loss), but for upgrading purpose you can instantiate without any parameter first.

    5. UdpNetworkDriver.Send() now takes an extra NetworkPipeline parameter, use the one you just created.
     
    li2343, ZuhairGhias and gooodpgr like this.
  4. i2winners

    i2winners

    Joined:
    Apr 21, 2019
    Posts:
    1
    @zhuchun can you share some code sample

    Code (CSharp):
    1. using System.Net;
    2. using UnityEngine;
    3.  
    4. using Unity.Networking.Transport;
    5. using Unity.Collections;
    6.  
    7. using NetworkConnection = Unity.Networking.Transport.NetworkConnection;
    8. using UdpCNetworkDriver = Unity.Networking.Transport.BasicNetworkDriver<Unity.Networking.Transport.IPv4UDPSocket>;
    9.  
    10.  
    11.  
    12. public class ServerBehaviour : MonoBehaviour
    13. {
    14.  
    15.     public UdpCNetworkDriver m_Driver;
    16.     private NativeList<NetworkConnection> m_Connections;
    17.  
    18.     void Start()
    19.     {
    20.         m_Driver = new UdpCNetworkDriver(new INetworkParameter[0]);
    21.         if (m_Driver.Bind(new IPEndPoint(IPAddress.Any, 9000)) != 0)
    22.             Debug.Log("Failed to bind to port 9000");
    23.         else
    24.             m_Driver.Listen();
    25.  
    26.         m_Connections = new NativeList<NetworkConnection>(16, Allocator.Persistent);
    27.     }
    28.  
    to something like this?:
    Code (CSharp):
    1. using System.Net;
    2. using Unity.Collections;
    3. using UnityEngine;
    4. using Unity.Networking.Transport;
    5.  
    6.  
    7. public class ClientBehaviour : MonoBehaviour
    8. {
    9.     //You still define a UdpCNetworkDriver but instead of having a list of connections we now only have one.
    10.     //There is a Done flag to indicate when we are done, or in case you have issues with a connection, you can exit quick.
    11.  
    12.     public UdpNetworkDriver m_Driver;
    13.     public NetworkConnection m_Connection;
    14.     public NetworkPipeline m_Pipeline;
    15.     public bool m_Done;
    16.  
    17.     // Start by creating a driver for the client and an address for the server.
    18.     void Start()
    19.     {
    20.        
    21.         m_Driver = new UdpNetworkDriver(new INetworkParameter[0]);
    22.         m_Pipeline = m_Driver.CreatePipeline();
    23.         m_Connection = default(NetworkConnection);
    24.  
    25.         var endpoint = new NetworkEndPoint();
    26.         m_Connection = m_Driver.Connect(endpoint);
    27.     }
    28.     // Then call the Connect method on your driver.
    29.  
     
    ZuhairGhias likes this.
  5. Atriox

    Atriox

    Joined:
    Jul 13, 2013
    Posts:
    1
    After spending a little while toiling away at this I finally figured out how to get it working with some of the new updates after actually reading the source (I'm terrible at reading source :D).

    First off the proper way to use the NetworkEndPoint struct is this:

    Code (CSharp):
    1. m_Endpoint = new NetworkEndPoint();
    2. m_Endpoint = NetworkEndPoint.Parse("127.0.0.1", 9000);
    I'm linking gists of the non-jobified source for the client and server and hopefully it helps anyone else out with this! Also note you have to do something with the pipeline, just used what was in the documentation, not entirely sure how to do it with a different pipeline, nor do I fully understand it yet. Still reading :)

    ClientBehavior.cs:
    https://gist.github.com/duynguye/2ae6680068c44e574390d7e9874d4f83

    ServerBehavior.cs:
    https://gist.github.com/duynguye/7b6b0828a89ab4e4b7da769f86adc1fe
     
    klassicd, Ttravi, Thasiroz and 3 others like this.
  6. Bunzaga

    Bunzaga

    Joined:
    Jan 9, 2009
    Posts:
    202
  7. 4Xrn7oIe

    4Xrn7oIe

    Joined:
    Jan 29, 2016
    Posts:
    10
    Trying to work with Unity's out-of-date documentation and non-working examples in this case actually lead me into such a rage that, after years of working with Unity, I've finally given up and am working with Unreal, which has all the features you need to write a multiplayer game working, out of the box.

    I'm not going to try to express the sheer rage I'm feeling at the moment, but yeah, I hope this helps some of you. Unity has reliable UDP and replication working with all the bells and whistles you'd expect out of a "real" game engine. It's unfortunately that Unity doesn't have the respect for their customers to properly update a simple sample project or documentation. Another customer lost, I guess! Cancelling my subscription next.

    If you're interested, check this out:
    https://docs.unrealengine.com/en-US/Gameplay/Networking/QuickStart/index.html
     
  8. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Feel sorry for your situation @4Xrn7oIe , but I would say the word "multiplayer" is much more complicated than a transport layer we're discussing here

    Actually I've moved to LiteNetLib instead. The Unity Transport package is freaky and over-engineering somewhat if you're not making an ECS game, any other alternatives like LiteNetLib or ENet would make things much easier
     
  9. 4Xrn7oIe

    4Xrn7oIe

    Joined:
    Jan 29, 2016
    Posts:
    10
    @zhuchun, yep, but a proper networking subsystem is what you'd expect from a game engine, no?

    It's unclear to me why they're implementing an extremely brittle, low-level layer like this without something immediately useful on top of it. For example, why is there no way to specify which properties of your GameObjects you want replicated and how (reliably/unreliably), etc?

    I don't pay for a game engine so that I have to engineer this stuff myself. Unreal has what you'd expect to build a scalable multiplayer game out of the box, and for me at least, that's what I need.

    And no, I do not want to use a third party library (which could go away at any point) to build my game! No thanks! :)
     
  10. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    High-Level API is great, but you may already know that Unity screwed it up once years ago so they deprecated both Hight-Level and Low-Level API and start to build a brand new network system, its Low-Level API is the transport layer and High-Level API is NetCode

    In general, most game makers would preferred Low-Level API as it gives developers more freedom to fine-tune the game. High-Level API usually doesn't scale very well.

    Personally, I'm not worried about open-sourced 3rd party libs as most of them are battle proved and stable.