How do I call C++ from a Blueprint project to store variables in a database?

Hello AnswerHub,

Me and my brother are developing a game that has to store user data into a database. For example their level, exp amount, amount of health, things like that. We both however come from a webdevelopment background and have no experience in C++ whatsoever, which is why we went with blueprints.

I’ve searched across all of the interwebz but I haven’t been able to find out how to ‘do a call to C++’ from a blueprint to make a connection to something like MySQL. Is something like this even possible to do, and if so… how?

If this isn’t possible, could you then perhaps supply me with alternatives? I would really like to avoid having to learn C++ from scratch.

Thanks in advance,

Kevin

You likely shouldn’t be connecting to the DB directly through C++ to begin with. It’s likely best to setup a PHP API/REST to handle DB communication. Doing that you should be able to use the Blueprint nodes for communicating via PHP to store info in MySQL.

If the server executable is the only thing that has access to this code then sure.

In that case writing a plugin for UE4 that can interact with the MySQL C++ driver. With that said the MySQL C++ driver is blocking and as such any communication with the DB needs to be done in a thread so that it doesn’t cause the game to stop and wait.

You mean connecting to DB from client-side, server side is safe… atleast same as safe as PHP :stuck_out_tongue:

You can’t call external native code (because at that point they aren’t C++ anymore) from blueprint, instead you need to write BlueprintCallable C++ code that will bind some external library to blueprint. I know some people been interested in DB support in UE4 so you might find some ready plugins

Try out this plugin, we use this for our database right now. Everything is in blueprint.

Thanks alot for that plugin!

Thanks for taking the time to reply, Duncan supplied me with a plugin like you’ve mentioned.

Thanks for taking the time to reply, do you perhaps have a link I can visit so I can learn how to setup communication with a PHP API/REST via Blueprints?

I’m trying to install this on UE 4.6.1, says the build fails because plugin was made with different version of engine. I’ve taken a look and it seems its compatible with 4.6.0 only.

Am I missing something, is there a way around this, and if not, is there an alternative?