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

Unity Transport and Netcode

Discussion in 'Unity Transport' started by cerestorm, Jan 21, 2022.

  1. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    I'm feeling a bit slow on the uptake in regards to Unity transport. I see a lot of information on how to use it, but I can't find anything explaining the benefits of using it over the UNet transport in Netcode and why I would choose one over the other.

    As it appears to have a different configuration to the UNet transport, how does it just work as a drop in replacement?
     
  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    428
    One benefit is that it will actually be supported going forward. UNet has been deprecated for a while now. Eventually it will be removed, and then the UNet transport for Netcode will have to be removed too. At that point Unity Transport will be the only officially supported transport.

    Also, if you think you might use the Unity Relay service, using Unity Transport is the only way to do so currently. So that's another benefit.

    You are correct that it's not exactly a drop-in replacement. Switching from the UNet transport to Unity Transport shouldn't require any code changes in most cases, but it will require at least setting the correct IP address and port in the inspector if they were changed from their defaults.
     
    cerestorm likes this.
  3. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    Thanks Simon, I'll definitely switch over at this point then.

    The reason I mentioned about it being a drop-in replacement is that the documentation mentions the use of ServerBehaviour, NetworkDriver and the like, and yet I can switch to the Unity transport without any of that and it just works. I'm trying to get my head around where the magic happens.
     
  4. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    428
    Can you point me at the parts of the documentation that were confusing? If the documentation is misleading, we definitely need to address that.

    From the point of view of someone using Netcode for GameObjects, using Unity Transport instead of the UNet transport should make little difference. The main APIs (NetworkManager, NetworkObjects, RPCs, etc.) are the same.
     
  5. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    It's not the documentation, more me trying to understand how Netcode and Unity Transport interface with one another. Perhaps the custom transport code would shed some light on this.

    The biggest issue I have right now and it's why I'm looking at Unity Transport is I need reliable sequenced connections for my project which I don't think UNet provides. Presumably there are no limitations using Unity Transport with Netcode?
     
  6. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    428
    I believe the UNet transport does provide reliable sequenced delivery. Messages sent with
    NetworkDelivery.ReliableSequenced
    or
    NetworkDelivery.ReliableFragmentedSequenced
    will be sent in this manner. In that regards it behaves the same as Unity Transport.

    Regarding limitations, of course we are still in prerelease so there are a few quirks still being worked out. In relation to reliable and sequenced delivery, Unity Transport currently has a limitation on the maximum message size it can handle. The limit is ~44KB but we have a fix incoming that will remove that limitation (hopefully it will make it to the next release).
     
    CosmicStud likes this.
  7. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    I looked at NetworkDelivery, but got the impression that was only for messages rather than NetworkVariables and the like, which is what would make my life a lot easier. Is it possible for all changes made to network objects on the server to happen in the same order on the client?

    Sorry for the barrage of questions. I'm stuck at a point in my project coming up with poor solutions to work around out-of-sequence changes.

    I did see mention of that fix and that should help as I've been limited in the number of network objects I spawn during initialisation.
     
  8. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    428
    Unfortunately I'm not familiar enough with the Netcode for GameObjects code to answer that question. You might have better luck on its dedicated sub-forum.

    Edit: Oops, forget that, I see you already posted there.
     
  9. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    Yeah, I'll keep my finger's crossed for an answer. Thanks for all your help.