Download

UE4 and MySQL

How would I go about connecting my unreal engine game to MySQL so that I can save a player’s inventory, create a login system, and allow for multiplayer? Is that even possible within blueprints?

Yeah sure. With the help of some API parser library or coding your own. I use VaRest to interface with my API built on node.js. But you could just as easily throw a quick api together in PHP that interfaces with a mysql database. Then you make API calls from UE4 in blueprint using for example VaRest. GitHub - ufna/VaRest: REST API plugin for Unreal Engine 4 - we love restfull backend and JSON communications! But there are others out there.

Thanks for the help on this. What did you use MySQL to store on your project?

Also, do you know of any good API for interfacing with a mysql database like how you mentioned (PHP is not a strong suit of mine)?

I don’t use MySQL but it would be easy to integrate if I wanted. But node.js just holds onto a persistent object for me so I don’t have to store it in a DB. The API will require that you write the code and build the logic. You’ll have to create “end points” that grab data from the mysql database and display it. Though I can show you an example of how I use it. This is an API skinned down to the bare bones (http://pastebin.com/qzaYmGYp). It requires you to hit an endpoint like: http://www.com/kv_pairs. It will store any key value pair you post to it as long as the process stays running. You can retrieve the values by doing a GET request on that end point. There is a chrome app called Postman and it will be your friend for testing your API outside of your game. You’re more than likely going to have to do some coding. I’d google for php/mysql tutorials to get started or any other type of web language be it python, node.js, any of the technologies. Trust me there are tons of them out there. Be careful of security though and mysql injections.

I would not call MySQL directly from UE4. I would implement a layer between those 2. From UE4 call a webservice. In that webservice call MySql. This way you have maximum freedom. You can always switch database without changing UE game code. Or you can run the database on a different network(somewhere in the cloud for example).

How to use webservice in blueprint?

@mayaping as discussed above, you will need a plugin, e.g. GitHub - ufna/VaRest: REST API plugin for Unreal Engine 4 - we love restfull backend and JSON communications!