Using Unity Types on a Server?


I'm just starting work on a game that'll use an authoritative server (based on the LoadBalancing Photon Server application), and I need clients and the server to simulate what is going on in the game. While there won't be intense physics or anything, it would be handy to be able to use the same simulation code on both client and server. The easiest way to do that that I can see is if I could use the standard Unity Vector types and Mathf functions. Is there a way to do this? (Perhaps I can add a reference in my project to some Unity assembly?)

Barring that, are there reasonable vector/math libraries I could use on the server? (Maybe the DirectX ones, maybe some not tied to them), or should I consider rolling my own?

Any insights, especially ones that make it easy to re-use the same simulation code on both client and server, would be appreciated.


  • HI,

    Using same libraries on both server and client side may be a good idea. Any library should work. But i'm not sure if it's possible or reasonable to use entire Unity library on server side. I think lot of other good math libraries exist.
    The only thing you may need to care about is custom types de/serialization if you are planing to send data of these types over network.
  • Using unitys stuff would be silly given that you could just create a common lib for your client and server and makes sure logic and functionality is shared.

    I am have already done most of the auth stuff based off the load balancing and heavly modifying pun.

    Im using the idea of masterclients to do the simulation stuff. I looked at bullet physics and all the various libs, but I was like nope nope nope.... getting a physics engine to work ontop of a networking engine and keep everything within realms of sanity for hardware usage.. nope nope nope.. Even on a little game I think you under estimate the trouble you are signing up for. I went waste deep in that and backed out quick.

    Use master clients, you can start a unity client headless and pass normal application parameters into the start up.

    Have your server start these up when people join a game, direct your master client set up to the game first, then load in your players. After that just act like everything is pun.

    I think that you will find that no matter how you slice it, you will be using some kind of external application to connect to your servers to do even basic in game logic. There is no more lag then if you were using any other distributed networking system. It separates your game logic from your network proccessing logic (Which is important).

    have many more reasons why this system is a better way to do it. I have tried lots of various ones as well. If you would like to talk more about it, feel free to send me your skype in a message and we can do a call to talk about the ups and downs of both systems.