Unity won’t link to object in external lib if using modern Rpc call notation

So I’m trying to have a base class I can derive from in a separate Client and Server projects, as such I’m placing it in a third library project that I call shared. Basically:

*Client (Unity project)
*Server (Unity project)
*Shared (Static Lib)

So since images help:

In this one it fails to compile while using the current notation for RPCs


If using the old RPC notation it compiles with no problem


Is this a bug? Can I not have an abstract class that I use as base in both client and server form the lib?
(I know it’s not abstract atm I was trying stuff to understand what was the issue before)

I highly recommend not creating two unique projects in order to define server and client builds. While it might seem like a good way to organize things, you will quickly run into issues pertaining to GlobalObjectIdHash generation (what is used to uniquely identifier a network prefab) and other issues like you pointed out with RPCs.

You should take a look at this overriding scenes and prefabs example project to see how you can have uniquely loaded scenes (on server or client side) and prefab instances (server side version and client side version).

Netcode for GameObjects doesn’t support having multiple projects at this time.

1 Like

Hello Noel, I’ve tried it and find it a really unworkable solution, with just a few points of logic, the project became confusing and hard to follow the code logic, debugging is hell cause you can’t launch two instances of the same project.

Having selective compiling for server and client is interesting but makes the only solution I’ve found to launch several instances not work, because parts of the code base are not available in different build modes.

I’m actually in the process of changing from single project to separate projects.

Ok,
So you can start a NetworkManager as just a server (NetworkManager.StartServer) and either create a build and connect locally or use the Multiplayer Play Mode tool. I would recommend developing like this and as you approach milestones you can make a dedicated server build to validate that.

Did you look over the example project already?

1 Like

Sounds like you aren’t aware of Multiplayer Playmode package. :wink:

It launches up to three additional editor instances from within the main editor.

Because of the lack of client-server code separation? You can do that in a single project. Eg you have a PlayerServer and PlayerClient scripts which reference each other.

I don’t recall exactly but if I do, then RPCs in base classes are not supported.
You can achieve what you want with custom messages though.

Also: I absolutely agree on avoding the split project notion. This will make almost everything more challenging, and any workflow issues you have in the single project merely need some reflection on alternative techniques other than breaking the project into two, which would be a massively complicating solution. For instance you can make an Assembly Definition for Server-only code and similar architectural changes.

Most importantly: split projects are hardly used by others so if you run into any problems not only will they be serious and difficult to debug but you will also hardly find any help on the Internet.

1 Like

@NoelStephens_Unity and @CodeSmile thanks for your inputs.

I did look it over but it didn’t jump out as solving the my previous problems, my mistake it seems.

I’ll give a look into that solution of using Multiplayer Playmode.

I wonder if it will give me breakpoint debugging on both client and server, but if it doesn’t require me to build them each time I try to understand what’s happening it should be acceptable.

Does it also build taking into account the Directive definitions of code to be built on server vs client?

Yes you can set breakpoints at least for the main editor. I can’t recall if virtual player breakpoints also trigger, worth giving a try. I generally use the main editor in the role that I want to test and debug so this is why I can’t recall.

With the tag system and a launcher script responding to the tags, it’s easy to set up any player as either the Server, Host or Client.

With the Dedicated Server package installed you can also use Multiplayer Roles to strip assets and code from builds, both for server and clients. MPPM supports this with its dropdown to set each player as either Server, Client or “Server and Client” (Host). This allows you to test, from within the editor, whether the code/asset stripping of Server and Client work without issues - which would otherwise be very time consuming to figure out.

Say for instance you have a script with a Renderer component reference. If that script runs on the Server build and it accesses the Renderer reference you’ll get an exception if you have set the Server builds via Settings to strip all rendering components (highly recommended to conserve server-side resources).