MySQL, Unity, and SmartFoxServer – further deliberations

(In this first of a four part series of posts I will document my endeavours in getting Unity and MySQL to speak to each other through a SFS2X extension.)

Hi folks,

So, finally after much ado, I’ve got around to applying source control to my Unity project, for both the game client and also the game server (using SFS2X) as per this tutorial here.  I also discovered that I hadn’t yet installed MySQL yet, only the workbench.  That was easy to fix though, following this tutorial here.

I was quite excited to gather that SFS2X version 2.8 was recently released, and it now has not only better support for MMO type games, but also better support for writing data from Unity to a database – both goals that I am interested in achieving with my project.  One of the new features is the introduction of an area of interest (AoI), wherein the server will only update objects / send messages about the game world to a client that are within that client’s AoI.  See here.  There is also the concept of “MMOItems” that is introduced, which seems like a neat way of handling changes to the world state triggered by players that are outside a client’s AoI.

To recap my general first “hello MySQL-Unity-SFS2X” objective, I wish to store a single row of data for a given user into the database, with columns Username, Password, x, y, z position, and x, y, z rotation – so eight pieces of information in total.  I then would like this to be updated every time the user logs out, and read every time the user logs in.  In this way I should have game functionality that allows a user to re-enter the world in the same position they left it – quite a handy feature to have.

Naturally, this would allow me to springboard into more complex features later on in the development process.

So upon completion of the first part of the MySQL Server installation tutorial above, I linked MySQL Workbench to my database, and created a schema “rpg_mmo_smartfox” in same.  Consequent to this I created a table with the following columns (note: I changed VARCHAR(45) to DECIMAL(10,0) subsequent to this screenshot):

SmartFoxServer RPG MMO first table

I then inserted the following row into said table:

Naturally the x, y, and z position is the most important aspect of the program to get right.  On examination of the code on the server, I obtained the correct starting location / spawn point:

private static Transform[] getSpawnPointsRPG() {
Transform[] spawnPoints = new Transform[3];
spawnPoints[0] = new Transform(850, 10, 1054, 0, 0, 0);
return spawnPoints;

So the location of the initial spawn point in the game world is 850, 10, 1054, with rotation information 0, 0, 0. Therefore it seems logical to use that as my initial row. A simple modification of my table, and I am now ready to start trying to learn how to connect to the mysql database ingame and update rows on logout, and read rows on login.

I suppose more generally it would be better to have 6 extra columns, too, for the player spawn location (eg, the concept of “hearthstone point” in a popular mmo that some might be familiar with).  So on some further reflection, I decided ultimately to have 12 columns in total for position information: player last seen location, and current spawn location.  I set the new columns to have the same set of values as the existing columns: I would like on creation, a player to have the same last seen position as their spawn location.

So then the idea would be that the spawn location would have to be changed by a player deliberation, whereas the x,y,z position and rotation information would be more dynamic.  And the spawn x, y, z location and rotation information would be used by the game if the player needs to be respawned.

Huzzah! In this era of big data, I have now done my part to make that data just a little bit bigger.

Tags: ,

3 Responses to “MySQL, Unity, and SmartFoxServer – further deliberations”

  1. SutoCom Says:

    Reblogged this on Sutoprise Avenue, A SutoCom Source.

  2. MySQL, Unity, and SmartFoxServer – implementing the functionality | Where's my hat?! Says:

    […] Random musings of a demonic entity « MySQL, Unity, and SmartFoxServer – further deliberations […]

  3. MySQL, Unity, and SmartFoxServer – location persistence in the game world | Where's my hat?! Says:

    […] Post One : Preliminaries with MySQL […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: