- Convert Unity scene data into WorldState.
- Push agent positions, navmesh availability, events to middleware.
- Fetch batched AgentCommands from middleware.
- Apply moves, animations, interactions in Unity.
- Optional debug overlay for goals, LOD, and current action visualization.
// Initialization and shutdown
bool InitSimulation(int maxAgents);
void ShutdownSimulation();
// Main simulation step
void StepSimulation(float deltaTime, ref MarshaledWorldSnapshot marshaledSnapshot,
[Out] AgentCommand[] agentCommands, ref int commandCount, int maxCommandCapacity,
Vector3 cameraPosition);
// Agent management
int AddAgent(Vector3 initialPos, Quaternion initialRot, int initialGoal, int initialState);
void RemoveAgent(int agentId);
int GetAgentCount();
// Debug data retrieval
void GetAgentData([Out] AgentDebugData[] agentData, ref int count);- Avoid per-agent callbacks to engine for performance.
- Batch movement and events to minimize frame overhead.
- Design for expansion to Unreal or Godot.
Integrating AgentSimMiddleware with engines beyond Unity (e.g., Unreal Engine, Godot Engine) will follow a similar adapter-based architectural pattern. The core principle remains isolating the engine-agnostic C++ simulation logic from engine-specific data handling and rendering.
General Approach:
- Engine-Specific Adapter Layer: A new adapter layer (e.g.,
UnrealAdapter.cpp/.horGodotAdapter.gdns/.gdfor scripting APIs, or C++ for native integrations) would be developed for each target engine. This layer acts as the primary interface between the engine's world state and the C++ core. - World State Marshaling: The adapter would be responsible for gathering relevant world data (e.g., entity positions, obstacle geometry, event triggers) from the engine's API and marshaling it into a
WorldSnapshotstructure that the C++ core can understand. This process is analogous to howUnityAdapter.cscurrently populatesWorldSnapshots. - Command Translation: After the C++ core's
StepSimulationmethod processes theWorldSnapshotand updates agent logic, it generatesAgentCommands. The engine-specific adapter would then receive these commands and translate them into native engine calls (e.g., moving an Unreal Actor, playing a Godot animation, triggering an event within the engine). - Debugging & Visualization: Just as with Unity, the adapter would provide mechanisms for exposing C++ core debug data back to the engine's editor or debugging tools for visualization (e.g., agent paths, current goals, LOD states).
- Build System Integration: The C++ core, being CMake-based, can be easily integrated into other engine's build pipelines (e.g., as a module for Unreal Engine or a GDExtension for Godot).
This modular approach ensures that the high-performance C++ simulation logic remains reusable and decoupled, while engine-specific concerns are confined to their respective adapters.