Before You Start
- Keep your MySQL or MariaDB server reachable from the machine running the game or editor.
- Know the host, schema/database name, username, password, and port. The default MySQL port is
3306. - Create a database user with only the permissions your Blueprint flow needs.
Where the SQL Session Lives
The live MySQL session is owned by the MySQL Game Instance subsystem, not by the level actor. Open Level destroys world actors. It does not close the SQL connection, drop Connection IDs, or cancel in-flight queries.
| Object | Survives Open Level? |
|---|---|
| MySQL Game Instance subsystem | Yes, for the whole play session |
| Native SQL connection and Connection IDs | Yes, until you close them or the game ends |
| MySQL connection actor in the level | No. The next map's actor adopts the same session |
| Events bound on the destroyed actor | No. Bind the subsystem if your widget stays alive across maps |
ℹ️ Login map to game map: Connect once on the login map, keep the
ConnectionID (usually 0), open another level, then keep using that same ID. Do not call CreateNewConnection again just because a new actor spawned.
Blueprint Connection Steps
- Place a
MySQLDBConnectionActorin the map that first needs the database, or spawn the plugin'sBP_MySQLDBConnectionActor. - On login,
BeginPlay, or your setup event, callCreateNewConnectionwithServer,DBName,UserID,Password, andPort. - Add the actor event
OnConnectionStateChanged. Store the returnedConnectionIDwhenConnection Statusis true. - If a widget, Game Instance, or Player Controller will outlive that map, also get
Get MySQL Subsystemand bind the subsystem'sOn Connection State Changed,On Query Select Status Changed, andOn Query Update Status Changed. - Optional: assign a
MySQLConnectionOptionsasset on the actor for SSL, timeout, read-only, or multi-result settings.
After Open Level
- Place a MySQL connection actor in the destination map as well, including the login map if you return there.
- That new actor registers with the Game Instance subsystem on
BeginPlay. It does not close existing connections. - From a persistent widget, call
Get MySQL Subsystem, thenGet Active Connection Actor. Do not keep a hard reference to the actor from the previous map. - Call
Has Connectionwith your storedConnectionID. If it is still valid, runSelectDataFromQueryorUpdateDataFromQueryon the new actor with that same ID. - Only call
CreateNewConnectionagain if you actually need another SQL session.
⚠️ Stale actor references: A widget that still calls select or update on the destroyed login-map actor will get no events. Re-resolve the actor from the subsystem, or bind the subsystem events once and keep using the stored Connection ID.
Run a Select Query
- Wait until
OnConnectionStateChangedreports a successful connection and aConnectionID. - Call
SelectDataFromQuerywith thatConnectionIDand your SQL select statement.
SELECT id, display_name, coins
FROM players
ORDER BY coins DESC
LIMIT 10;
- Use
OnQuerySelectStatusChangedon the current actor, or the matching subsystem event if the widget outlives the map. - On success, read
Result By Column(MySQLDataTable) orResult By Row(MySQLDataRow). - Match the event's
QueryIDif several selects can be in flight at once.
Run an Insert, Update, or Delete
- Call
UpdateDataFromQuerywith the sameConnectionID. - Use
OnQueryUpdateStatusChangedto show success or the returned error text. - Use
UpdateDataFromMultipleQuerieswhen you need several statements in one queued task.
UPDATE players
SET coins = coins + 100
WHERE id = 42;
Using the Dedicated MySQL Actor
- Place one connection actor per map that needs to talk to MySQL. Several actors in the same play session share the Game Instance session.
- Call
CreateNewConnection. TheConnectionIDarrives onOnConnectionStateChanged, not as a return pin. - Pass that
ConnectionIDinto later select, update, image, and close nodes. - Use
Get Last Query IDor theQueryIDon completed events when you need to match a result back to the UI request that started it. - Create a
MySQLConnectionOptionsasset when you need SSL, timeout, connect attribute, read-only, or multi-result settings editable outside the Blueprint graph.
Closing Connections
- Call
CloseConnectionwith aConnectionID, orCloseAllConnections, only when you intend to drop the SQL session. - Leaving a map, streaming a level, or returning to the login map does not close the session.
- The session is closed automatically when the Game Instance shuts down, including quitting the game or stopping Play In Editor.
MySQL Notes
- Use MySQL or MariaDB SQL syntax for queries.
- Keep the stored
ConnectionIDon Game Instance or a persistent widget if login UI and gameplay maps both need it. - Image and BLOB Blueprint nodes exist on the MySQL actor. For the shared DataBases package, treat Microsoft SQL Server as the documented image workflow unless your MySQL build exposes those nodes.
Troubleshooting
| Symptom | Cause | What to do |
|---|---|---|
Select and update work on the login map, then stop after Open Level and returning |
The widget still talks to the destroyed actor, or it created a second connection instead of reusing the ID | Get Get Active Connection Actor from Get MySQL Subsystem and reuse the original ConnectionID |
| Events fire once, then never again after travel | Actor Blueprint events died with the old map | Bind the Game Instance subsystem select/update events from a widget that lives on Game Instance or Player Controller |
| Connection ID 0 is missing after travel | The graph called CloseAllConnections or created a new session and discarded the old ID |
Do not close on EndPlay or map travel. Check Has Connection before creating another session |