Sunday, April 29, 2012

I Hate Databases!

After a full day messing with accessing databases in Unity3D, I have come to a troubling conclusion.  Databases and Unity3D don't mix well.  I think the main problem stems from Unity's need to dynamically generate code at every execution.  That means a routine to access a database will vary slightly every time the game is closed and reopened later.  Consequently, the "newly" generated code can't access data saved by a "previously" generated code.  This "feature" has given me a massive headache.

Since Unity will dynamically create code, the best bet to incorporate database routines into Unity is to create an external .dll file to handle database functions.  By building the database routines in Microsoft C#, the routines should be pretty "static" compared to the "dynamic" nature of Unity routines. 

To make this work, I'll generate a Battlestar namespace and .dll file.  It will contain various managers.  I'll have to build the stuff over time; so, Battlestar.dll will start with a BulletManager.  To access the database routines in Unity, the following code should work:


Load will be a defined procedure in BulletManager and will need a path name (which will reside in the ResourceManager; so, we won't have to figure it every time we need to access the database) and the bullet type.  Load, itself, will open the database at the path name and look for a bullet of the specified type.  vBulletData will be a variable designed to hold the bullet data retrieved the database.  After getting the data, it can be manipulated normally.

Missiles and Countermeasures will require a similar setup to load data into these commonly instantiated (created) game objects.  In addition, the future resource manager will utilize this concept.  The Battlestar.dll file will grow over time. 

Another major issues is data entry into the database.  Currenty, there is no way to easily create or maintain the database.  I'll have to create a database editor in Microsoft C# (using the Battlestar.dll) to access the database from a developer perspective.  This will allow the developers to add different styles of bullets the game.  Currently, the only type of bullet available is a "standard" type.  In the future, there are plans to add a "armor piercing", "high explosive" and other types.  The same thing goes for missiles and countermeasure.

I spent a majority of the last twenty years developing and deploying databases.  This is probably the first time that I abolutely hated databases.  Unity just created so many headaches and routines (at least in design) that have worked for me for over two decades just didn't cut it.  It just took forever to learn that the routines weren't flawed; it's just how Unity's setup causing issues.

No comments:

Post a Comment