- Home /
Embedding Unity physics on a server.
My team and I are currently developing a flexible multi-use server software for use with Unity. Of course we'll need a server side physics engine.
The question is:
Is there a possibility to use a raw Unity physics engine without starting a whole Unity instance with graphics and unneeded computations? If yes, where should I look? If no, what is the best way to disable all unneeded graphics and computations in Unity's instance to reduce an overhead to a minimum. Also how does it look from the legal side to use a part of Unity for commercial use.
Hi, interesting challenge! If there is nothing in Unity to do this (except having a source license), maybe you can trick the Unity player with a custom made environment. For example, if your server tech can run on Linux, I think you can find source code for the Opengl drivers and then customize your own. This version would just "return" for most calls, same for sound or inputs. This may also allow you to run multiple instances on a machine/V$$anonymous$$ as it's usually done for servers instances. You could also fake other OS calls, for example to have more control on the timer. This would be a big development though, maybe some of this tech already exists in cloud/V$$anonymous$$ related developments.
Be aware that Unity physics, like all client physics, is designed to make use of the whole machine for processing power. Unless you intend to run one server per session you may have scaling issues. (And consider the cost of one server per session carefully.)
ALSO Unity uses PhysX which pushes the physics down to the GPU if its available. However, a cloud machine is not likely to have a GPU.
There is a lot more to achieving scalable game servers then just running a headless copy of the client code.
I didn't know about headless mode. $$anonymous$$aybe it'd do the trick . But I'm a little bit scared that responses would be too long. We already use Erlang for load balancing, java for business logic and if I added a cluster of unity instances it'd go through
client -> load balancer -> logic server -> physics server -> logic server -> load balancer -> client.
I'm afraid that even in case all of the machines are on one local claster it could be a big overhead
You are smart to be concerned.
The "comma wisdom' on Unity for handling lag really doesn't handle it very well. You can try simple linear prediction but, given the fact that there are forces constantly at work on the object in a Unity world, its likely to go [pretty wrong pretty fast.
The right way would be to be able to run the entire physics simulation backwards and forwards in time based on delayed information and predicted scenario. Unfortunately, that would require much more access to the Physics layer then Unity gives you.
At risk of giving away my expertise for free... I suggest you think not in terms of remote simulation but rather in terms of "consistency checking" that what the client claims is reasonable.
(I actually DO have an idea for a prediction model that might work better. But its just experimental right now and i have not yet gotten to implementing and testing it.)
Answer by ZenithCode · May 01, 2014 at 03:51 PM
Yes you can. Its call batchmode or Unity headless mode.
https://docs.unity3d.com/Documentation/Manual/CommandLineArguments.html