Which would be the most appropriate Unreal object (or whatever) to use for attaching my custom data storage subsystem?
Is the GameInstance appropriate place or is there any higher level available from C++ code? I have read this:
but I’m not sure if this is the best solution, considering my requirements and implementation plans (see the details below).
The long story.
For my custom hobby multiplayer simulation project, I’m going to implement a persistent storage subsystem (for now I’m aiming at MySQL but I hope to implement it in abstract-ish manner so I could attach Redis or MongoDB or whatever later on).
I am mostly experienced with web app architecture but I’ve read lots of articles about game server architecture as well. So, now I’m feeling ready to get my hands dirty with some coding. After reading UE4 documentation and C++ beginner and plugin developer guide, I have only one question - where to attach my code?
Also, I have found some mysterious piece of API:
Hmm… maybe UE4 already supports custom data stores or is on its way to implement that…
Some requirements and implementation ideas which come into my mind:
- I don’t want to recompile entire UE4 engine, I want just to create a plugin which could be used in any UE4 game.
- the storage subsystem should exist as a single instance throughout entire game (even when switching between modes in UE4 editor / play / dedicated server etc.)
- the storage subsystem should have access to the global game configuration when it gets loaded - I’ll need the SQL server host, port, db name, user, password
- the storage subsystem should receive Tick events or should be able to run in a background thread. I don’t want to write to the storage on every Actor property change. Instead, I will use some dirty checking on all actors which have my custom Storable component to see if it has some pending writes and then write some of the pending updates at the right moments (will try different strategies - check for idle CPU or just use some timeout and distribute updates in batches to avoid flushing them at once and causing game jitter).
- the storage subsystem should have access to all the Actors in all the sublevels of the world root level (to support level streaming)
- later I might get fancy and implement transaction support to ensure that the actors which have Storable component marked with the same transaction ID get actually stored during single SQL transaction.
Also, I haven’t yet looked into UE4 multithreading facilities - in case if my storage subsystem runs in a dedicated thread I’ll have to use some lightweight locking mechanism on my Storable component to avoid race conditions… but these are just ideas and problems to solve as I go. At first, I need to get the right starting point.