A real-time, persistent multiplayer 4X space strategy game built in Unity, inspired by classic games like VGA Planets, TradeWars 2002, and Stars! The game combines long-term empire building with fast-paced trading in a shared, continuously-running galaxy.
Space4X creates a living, breathing galaxy where empires rise and fall over months while traders keep the economy buzzing minute by minute. The game runs 24/7 on dedicated servers, with all ships, starbases, and economies processing continuously whether players are online or offline.
- Unity + Mirror Networking - Authoritative server with client prediction
- MySQL Database - Persistent storage for galaxy state, player data, and game objects via MySqlConnector
- Configuration-Driven Design - All game mechanics controlled via editable settings files
- Dual-Scale Gameplay - Empire players act on hour/day cycles, Traders on minute/hour cycles
- BigBang System - Procedurally generates galaxies with natural star clustering and empty voids
- Persistent Universe - 5000x5000 sector galaxy with natural density gradients toward center
- Real-Time Processing - Server continuously processes ship movement, resource production, and fleet combat
- Ion Storm Weather - Dynamic hazards that move across the galaxy affecting FTL travel
- First-Person Flight - Pilot individual ships with full 6DOF controls through the galaxy
- Strategic Command - Issue orders to fleets and manage empire-scale operations
- Economic Simulation - Complex supply chains driven by player actions and NPC traders
- Asymmetric Gameplay - Empire builders vs Traders with different capabilities and objectives
- GAME_DESIGN.md - Complete gameplay design and controls
- CONSOLE_GUIDE.md - Console system usage and commands
- CONFIGURATION.md - Settings and server customization
- ConfgDetail.md - Auto-generated configuration reference
- The repository contains a filtered asset index that excludes Unity
.metafiles and backups. Seedocs/ASSET_INDEX.mdfor a human-readable index anddocs/ASSET_INDEX.csvfor a machine-readable CSV. - A companion
docs/ASSET_INDEX_REFERENCES.csvlists where important prefabs and prefab variables (for exampleplayerControllerPrefab,shipPrefab,starbasePrefab) are referenced in code. This was produced by scanningAssets/Scripts/for prefab variables and literal prefab paths to help locate where assets are instantiated or validated.
-
Install MySQL 8.0+ and create database:
mysql -u root -p CREATE DATABASE space5x; CREATE USER 'space5x'@'localhost' IDENTIFIED BY 'BigBang'; GRANT ALL PRIVILEGES ON space5x.* TO 'space5x'@'localhost'; EXIT; mysql -u space5x -pBigBang space5x < db/schema.sql mysql -u space5x -pBigBang space5x < db/seed.sql
-
Configure MySQL connection (optional - defaults work for local dev):
- For repo reference, copy
mysql_config.json.templatetodb/mysql_config.jsonand edit as needed (this file is for developer reference only). - For standalone server builds, place
mysql_config.jsonnext to the executable or inconfig/mysql_config.jsonon the server. - In the Editor the server will create a
db/mysql_config.jsonfrom editor defaults (if missing). Standalone builds will createconfig/mysql_config.jsonwhen starting if none exists.
- Open the project in Unity 2020.3+
- Load the MainScene
- Press Play to start a local server
- Press
~to open the console and type/help - Use WASD + mouse to pilot your ship through the galaxy
The game automatically generates a galaxy on first run and saves all state to MySQL.
The game uses MySQL for persistent storage:
- Entity State: Ships, starbases, and player data saved to
persist_recordstable - Order Queue: Queued orders stored in
orderstable - Contracts: Mission system data in
contractstable - Autosave: Server automatically saves world state every 60 seconds
- Server-Only: Database operations run only on dedicated server builds
- Config File: Connection settings in
mysql_config.json(auto-created with defaults)
See docs/Linux_Server_Setup.md for production deployment configuration.
- Movement: Ships have normal speed (0-100) plus optional FTL capabilities
- Orders Queue: Ships can be given multiple orders that execute in sequence
- Order Types:
- Move to location
- FTL Jump (traders only)
- Attack target
- Trade resources
- Patrol route
- Hold position
- Return Orders: Ships can be ordered to return after completing a task
- Customization: Ships are fully customizable with different classes and configurations
- Player starbases serve as production centers
- Build ships, research technology, store resources
- Multiple starbase types with different capabilities
- Configurable build times and costs
- Multiple resource types (Fuel, Minerals, Food, etc.)
- Resources produced by planets in star systems
- Dynamic pricing based on supply and demand
- Trading between players and NPC starports
The game uses a GameSettings system that can be configured via JSON:
{
"mapSizeX": 50,
"mapSizeY": 50,
"starSystemChancePercentage": 10,
"normalSpeedMax": 100,
"traderFTLJumps": 5,
"traderFTLCooldownSeconds": 300,
"startingCredits": 10000,
"serverTickRateSeconds": 1.0,
"persistentGameplay": true
}- Multiple playable races with unique bonuses
- Production, Research, Trade, and Military modifiers
- Configurable via
RaceConfigurationScriptableObject
- Multiple ship classes (Scout, Trader, Frigate, Destroyer, Freighter)
- Customizable stats: hull, speed, cargo, weapons, shields
- Build costs and construction times
- Configurable via
ShipConfigurationScriptableObject
- Various types: Outpost, Trading Station, Starbase, Fortress
- Different capabilities and costs
- Configurable via
StarbaseConfigurationScriptableObject
- Player creates account with username/password
- Assigned a race (or can choose from available races)
- Given starting credits
- A starbase is created in a random, unowned star system
- Player can immediately start building ships and giving orders
- Login: Player connects to the persistent game server
- View Status: Check ship positions, resource levels, and ongoing orders
- Issue Orders: Command ships to move, attack, or trade
- Build: Queue ships for construction at starbases
- Console Commands: Press
~to open the console for listing objects, navigation, and testing (see CONSOLE_QUICKSTART.md) - Logout: Ships continue executing orders while offline
- Return: Log back in to see progress and issue new orders
- Top-down view of the galaxy
- Scrollable map showing all sectors
- Star systems appear as dots/icons
- Zoom in to see planets, ships, and starbases within a system
- Ship movement trails show historical paths
- BigBang: Universe generation and initialization
- PersistenceService: MySQL persistence layer with autosave (server-only)
- OrdersService: Ship order queue execution system
- ContractsService: Mission/contract lifecycle management
- HazardsService: Dynamic space hazards (ion storms, anomalies)
- NetworkManager: Mirror server/host/client management with SectorInterest
- playerManager: Client-side player interface
- RTS_Camera: 2D scrollable camera system
- MapClick: Sector selection and interaction
- Built on Unity Mirror for client-server networking
- Server-Authoritative: All game state mutations validated on server
- SyncVars: Real-time state synchronization (hull, cargo, position)
- Commands: Client requests with
[Command(requiresAuthority=true)] - ClientRpc: Server notifications to clients
- SectorInterest: Players only observe entities in their current sector
- KCP Transport: UDP-based transport on port 7777
- Turn-based but we make it real-time
- Ship orders and waypoints
- Resource management
- Multiple races with unique abilities
- Fast-paced trading gameplay
- Port trading system
- FTL jump mechanics for quick movement
- Persistent universe
- Deep ship customization
- Strategic depth
- Long-term empire building
- Technology research
This is an active development project implementing a complete rebuild of the Space4X game based on classic 4X strategy games.
- ✅ Configurable universe generation
- ✅ Persistent server game loop
- ✅ Ship order queue system
- ✅ FTL jump mechanics for traders
- ✅ Player account system
- ✅ Starting starbase assignment
- ✅ Configurable game settings
- ✅ Race configuration system
- ✅ Ship template system
- ✅ Starbase configuration system
- 🔨 Ship construction queue
- 🔨 Resource production system
- 🔨 Combat system
- 🔨 Technology research
- 🔨 Enhanced UI for ship/base management
- 📋 Diplomacy system
- 📋 Alliance mechanics
- 📋 Territory control
- 📋 Victory conditions
- 📋 Leaderboards and statistics
This is a World Domination Software project. The goal is to create an engaging, persistent multiplayer experience that captures the best elements of classic space strategy games while adding modern real-time gameplay.