NetworkManager with separated code-projects for client & server

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…

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.

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…

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.

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 :frowning:

I don’t understand why you want to share client and server code in the same files in the first place…

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.

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 :frowning:


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

@theantranch, @mattmirrorfish, @willgoldstone

I tweeted (my first tweet ever! :stuck_out_tongue: ) @anon_4146493 (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…

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.

[Command]
public void CmdSomeCommand(){
       // ... Can be empty on client
       // On server
       // RpcSomeRpc();
}

[ClientRpc]
public void RpcSomeRpc(){
       // ... Can be empty on server
       DoSomethingOnClient();
}

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).

@VergilUa any chance of you setting up a ping-pong example for us?

If only I had time. :stuck_out_tongue:

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.

Tried that already… its just not working… (object syncing)

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.

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 ?

I do not. In fact, I use custom re-written network controller that allows lag compensation and interpolation. It’s based on this:
https://github.com/GreenByteSoftware/UNet-Controller

my whole goal here is to move away from self written stuff :frowning:

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