Search code examples
sqliteunreal-engine4

SQLite in Unreal Engine 4


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++?


Solution

  • 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();