- Home /
Web-Client / Dedicated Console Server?
I'm trying to get my head around the Unity structure a little bit here.
I understand that you can NOT create a Native .NET 2.0 Dedicated Server for Unity3d.
So what would be a good strategy for doing this:
- Client Web game
- Dedicated Server
- SQL Database
Three tier structure. I don't want all the code sitting in the Client side. For Size and Hacking reasons. I basically just want the Client to download models and request there actions from the server. So the Server dose all the game logic. and just tells the client, what to load and, where to place it. and what effects to run at what location.. so on...
Then the Server Accesses a Database Via Linq. Which will require .Net 3.5+ basically.
So if I was to reference the Network side of Unity somehow that would probably be ok.
I noticed that there is -batchmode command line argument. But this still means that I have to code all the game logic into the client unity3d game. Which means that the download would be far too large for the web, plus open the door to sniffers and hackers playing with the game. I Also noticed that you can use a activeX in a windows forms project. Would that be the way to go?
Just after Ideas and Guidance.
Thanks
Answer by jashan · Aug 06, 2010 at 05:50 AM
It actually is quite possible to have a .NET 2.0 dedicated server for Unity 3D. If you use Photon as networking middleware, that's actually even what you'd usually have.
Obviously, what you'll be missing with that approach as the scene hierarchy and PhysX and a couple of other really nice features that a game server implemented as a Unity project has. But whether you need that or even want to have that or not depends heavily on the type of game you're trying to create. In many cases, creating the server in Unity won't even be a good idea.
If you decide to do a pure .NET 2.0 server, you could still have some server features implemented as Unity game server by having those run as a service. See Porting Unity Networking to Photon for a discussion of a potential approach for this.
If you wait for Unity 3 - which shouldn't take too long to be released (it's currently in beta and if you preordered you might even have access to the beta builds), you should be able to use Linq inside a Unity game server.
Personally, I'd avoid access a SQL database directly from Unity ... but that's mainly due to my experiences with Unity 2.x (of which the Mono version has a couple of unpleasant bugs in the SQL Server drivers). So I'll probably switch over my database handling and "simple game logics" to a pure .NET server and handle some of the more complex stuff like physics in a separate Unity game server which acts as a service to the pure .NET game server. This also gives me some nice flexibility in regards to scaling which Unity networking wouldn't give me (e.g. connecting to multiple game servers).
Regarding keeping server-only code out of the client: I'm using compiler directives for that. Unfortunately, Unity doesn't properly support those, yet (and won't in Unity 3.0 - but I hope they'll get that in there for Unity 3.1). What I do as a workaround is have a script that replaces
#define SERVER //A
with
//#define SERVER //I
in all my code files via an editor script. That way, I can easily switch between "server-mode" and "client-mode". It's a bit hacky but it works and isn't too hard to implement.
And yes, you can use -batchmode for a standalone Unity game server (I'm doing that ;-) ).
If having this as a feature in Unity would be useful to you, consider voting up: Editor: Interface for listing preprocessor macros (#define) in build settings
Your answer
![](https://koobas.hobune.stream/wayback/20220613070604im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Server Side Highscore "There was an error getting the high score: 404 not found" 3 Answers
Microsoft SQL Server error. 0 Answers
Hosted Database for Mobile Game 0 Answers
php, sql security 3 Answers
Best way to connect to database for my mobile game? 3 Answers