Separate client and server builds

My project scripts are split up into folders, inside each there are Server, Shared and Client sub folders. I want to be able to create separate server and client builds with the server built using the Server and Shared folders, and the client with Shared and Client. How do I go about doing this?

I’ve had a play with assembly definitions but I’m not quite getting it and I’d be grateful of some pointers.

This is with Unity 2020.

Which networking solution?
With NGO you cannot do this. Fish-Net is the only networking solution thus far to support this out of the box, I believe as a postprocess step (stripping).

The reason why this won‘t work (without NGO/Unity supporting it) is that a server script eventually needs to implement a ServerRPC method. But clients need to be able to call that method, so they need to reference that server script. And once that reference exists, the server script is included in the client build. And vice versa for ClientRPC called by the server.

At best you can #if out the code of RPC methods based on a SERVER/CLIENT preprocessor defines that you set for a build but I think you will have to manually change those every time you make builds, or automate the build process to do it for you. This should work because a client isn‘t actually executing the ServerRPC method, hence that method‘s body can be empt in the client build.

IMO this is too much of a hassle with very little gain. You may want to limit this to very specific RPC methods but even so, the impact on size and memory usage is negligible, and the benefit of added security is really just security by obscurity so bot really worth pursuing. I always recommend to make that game first and make it so popular that players start hacking it and then, there‘s probabaly better ways to combat this than to remove server code from client builds.

1 Like

Thanks CodeSmile, yes this is NGO.

I don’t know if it is too much hassle, it shouldn’t be much more than building the separate dll’s and a few #if statements. At least that’s what I was hoping.

There’s good reasons to not include the server code with the client, will it really matter for what I’m doing, probably not but it’s the right way to do it and useful knowledge for the future.

Fair point about the rpc’s, this shouldn’t be too much of a problem in my case as I only have one ServerRpc and ClientRpc and all messages pass through them.