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

NetworkManager with separated code-projects for client & server

Discussion in 'Multiplayer' started by rob_vld, Oct 18, 2017.

  1. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    190
    Probably a longshot... but I am hoping to get into contact with people who have some experience and are willing to help out setting up a standalone server with connecting clients where both client and server code is separated...

    Right now I am struggling with the rules of ownership, also there seems to be an issue with the sync to clients that receive remote players positions...
     
  2. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    with "NetworkManager" in the subject, I assume you're using the HLAPI?

    If so, and you insist on keeping your projects separate, forget about using Commands & RPCs. You're pretty much just going to want to send basic messages back & forth, losing most of what makes the HLAPI handy.
     
  3. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    190
    Hey there... thank you for your reply...

    Why do you say that though? - i followed the "Merry Fragmas" FPS tutorial and it was mentioned it should be no problem...
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I don't see how it is possible to call a command or rpc in UNet if the script that has that command or rpc is not a part of the project. So the client needs the script with the command just to call it, even though the command is run on the server, and the server needs the script with the rpc even though the rpc is run on the client.

    Unless there is some cool trick to doing this that I'm not aware of.
     
  5. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    190
    I see...

    I always used networkClient/Server to achieve this... but for some reason i am failing so hard with inter/extrapolating objects movements...

    How the NetworkManager handled things seemed to be good to be true for my purpose :(

    I don't understand why you want to share client and server code in the same files in the first place...
     
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    This is a recurring complaint about the UNet design.

    For my project, I have it in the plan to try including all contents within commands or the important stuff in server side only scripts within an "#if UNITY_STANDALONE_LINUX" preprocessor directive block (client is win/mac, server is linux), or setup a custom global #define that indicates this is a server which I will remove or comment out when building the client. I haven't tested it to see if it is a viable solution yet though (if you try it and it is no good, sorry), its just the best idea I've been able to come up with where I believe I should be able to use the full HLAPI as intended but leave out a good portion of the server code in client builds.

    https://docs.unity3d.com/Manual/PlatformDependentCompilation.html
     
  7. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    190
    So, i considered something like this... but, isnt this the same as separating the code? you are building your server or clients without pieces of code here right?

    or are we talking here about things like for example a database hook up...

    i dont think this is possible and will get very messy :(

    ---

    do you know of any active unity officials on these forums maybe?

    @theantranch, @mattmirrorfish, @willgoldstone

    I tweeted (my first tweet ever! :p )@mikegeig (mikegeig was last seen here at Jul 1, 2012)

    on twitter https://twitter.com/Hoppertje2013/status/920900175186538496

    maybe you could reply to it and support this request, see what he has to say as he has not yet responded...
     
    Last edited: Oct 19, 2017
  8. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Until you're running scripts with same signatures and netId's on both client and server it will work. So you need only headers of methods. That's what we do.

    E.g.
    Code (CSharp):
    1. [Command]
    2. public void CmdSomeCommand(){
    3.        // ... Can be empty on client
    4.        // On server
    5.        // RpcSomeRpc();
    6. }
    7.  
    8. [ClientRpc]
    9. public void RpcSomeRpc(){
    10.        // ... Can be empty on server
    11.        DoSomethingOnClient();
    12. }
    As for how clean the concept is... Well it works, it fits the needs, and it cuts down LLAPI code a bit. Even though if I would've started project right now, I would've chosen LLAPI messaging system instead. Since it has more control on message serialization, looks more like "client-server", and do not rely on UnetWeaver or "host"-idea file structure (you don't need to have message handlers in same file or even authority for them to work).
     
    Last edited: Oct 19, 2017
  9. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    190
    @VergilUa any chance of you setting up a ping-pong example for us?
     
  10. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    If only I had time. :p

    You can try doing it yourself, it's not nuclear science. You can start with bruteforce solution -> copying all scripts from host setup and then sorting everyting you want in two separate projects.

    Also, make sure CRC check is disabled in NetworkManager settings.

    Though I should warn you, at some point you'll encounter netId missmatch bug (as in any Unet HLAPI project, but it seems to be occuring more often in two different scene PostProcessing).

    The only solution to that is to use HLAPI Pro.
     
    Last edited: Oct 19, 2017
  11. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    190
    Tried that already.. its just not working.... (object syncing)
     
  12. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Make sure you're not encountering bug mentioned above. And also double or even triple check that SyncVars/SyncLists/SyncStructs and messages are identical in both code bases.

    Also, "not working" means you have to debug more. Figure out what's the reason of it.
     
  13. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    190
    I tried to separate my example code from the merry fragmas video...

    the client syncing with the server works

    but the client is not showing movement of remote players, instead it is snapping their positions...
    while it does show rotation movement...

    After testing it seems to be CharacterController Sync related as it does work with Transform Sync

    @VergilUa do you use a CC ?
     
    Last edited: Oct 19, 2017
  14. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
  15. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    190
    my whole goal here is to move away from self written stuff :(

    ok, i am at a loss... i thought i figured it out, it was working! - but now the transform positions sync are jumping too


    now it feels as if you cannot have a(cli-srv) sync transform - sync transform or sync CC - sync CC but need sync transform - sync CC

    which makes no sense imo


    edit: and now its working again, without any changes
     
    Last edited: Oct 19, 2017