1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

Can the HLAPI be moved to its own namespace

Discussion in 'Multiplayer Networking' started by PhilSA, Mar 17, 2017.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    291
    Hi,

    While the HLAPI is great for people who want to get started quickly, some devs will prefer writing their own networking systems on top of the NetworkTransport (LLAPI) for better control over the architecture of everything

    I've started doing that, and there's something that really bothers me; both the LLAPI and the HLAPI are in the same namespace, and it makes everything really confusing at times. In order to avoid confusion, it needs to be 100% clear when something is part of the HLAPI, and when something is part of the LLAPI. It would also avoid naming conflicts for when I want to make my own "NetworkConnection" class, for example. Is there a chance they could be put in separate namespaces?

    thanks
     
  2. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    196
    Unity changing the namespacing as you have suggested would cause unet to break for many of us, as we eagerly inherit awaited updates of unity. So, this suggestion isn't really realistic.

    Although there is no right or wrong when it comes to namespacing (unless you're following some sort of pattern such as PSR namespacing which suggests that your namespaces match your folder structure) I don't personally think there is anything wrong with the namespacing. Everything within the UnityEnging.Networking namespace is in some way related, when you consider that the high level api is merely just functionality built on top of the low level api. It sounds more like there is an issue in your own namespacing.

    One general rule of thumb is to only ever place classes in a namespace that you manage. So for example if you're building a game called "space invaders", you might place all of the code related to that game in a "SpaceInvaders" namespace, because you personally manage that code. You wouldn't expect someone else to place code in that same namespace, because either you or they could generate conflicts as and when you or they make changes to the code.

    So if you are having conflicts due to the creation of a NetworkConnection class in your code, it's either because your class doesn't exist within a namespace, or because you've tried to put it within UnityEngine.Networking, which as a rule of thumb you shouldn't, because you don't manage that namespace. I would recommend placing all of your code in your own managed namespaces.
     
  3. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    4,352
    You could create methods in some custom wrapper namespace of your own, to segregate HLAPI and LLAPI.
     
  4. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    291
    Pretty sure it would be trivial to handle this in the script updater. It would be as simple as adding a "using UnityEngine.Networking.HLAPI" in every class where an HLAPI type is detected
     
    dadude123 likes this.
  5. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    196
    This type of "fix" where the script updater injects code into user-defined scripts would definitely be reserved for desperate measures, such as major performance enhancements and/or major bug fixes, since there are a number of problems involved in making this type of modification to scripts that are not managed by unity.

    Again, there's really no right or wrong here. You could certainly argue that the namespacing could be better (depending on who's looking at it, the namespacing could always be better. That's the beauty of namespacing...), you could never truly argue that they've gotten it wrong. If you feel strongly about it though, feel free to use the bug reporting system. If you get a response, you'll likely get something similar to what is stated above, otherwise you might get a more detailed response than I can provide.

    Either way, good luck with your game!