SQLite in Unreal Engine 4

8.4k Views Asked by At

How can I interact with my own SQLite databases in Unreal Engine 4? Can it be done via blueprint and C++ or would it have to be purely C++?

2

There are 2 best solutions below

0
user3278897 On BEST ANSWER

Accessing SQLite from Unreal Engine can be done either from the blueprint (I haven't done it), but, check the TappyChicken blueprint example, the SaveGame class can store / load many variables through any event you want. Also here is a good video on YouTube:

http://www.youtube.com/watch?v=v0WRumU-gOk

In regards to the code, I use https://github.com/afuzzyllama/DataAccess. Try it out. It can save UObjects to a local database, sqlite.

For example:

TSharedPtr<SqliteDataResource> DataResource = MakeShareable(new SqliteDataResource(FString(FPaths::GameDir() + "/Data/Test.db")));
DataResource->Acquire();
TSharedPtr<IDataHandler> DataHandler = MakeShareable(new SqliteDataHandler(DataResource));

UTestObject* TestObj = NewObject<UTestObject>();

// Create a record
DataHandler->Create(TestObj);

// Read a record
DatHandler->Read(/**record id*/ 1, TestObj);

// Update a record
TestObj->SomeProperty = "some value";
DataHandler->Update(TestObj);

// Delete a record
DataHandler->Delete(TestObj);

// This shouldn't be necessary since this should be run when the TSharedPtr runs out of references
DataResource->Release();

1
Rolthar On

I used the VaRest Plugin (blueprints available) which communicated to my server to handle to database entries, you might find this route easier.

https://wiki.unrealengine.com/VaRest_Plugin