If your game uses multiple simultaneous Worlds that need to load the same terrain, such as an MMO game with multiple independent servers or rooms, you can conserve memory by setting up all of your Worlds to share the same static pre-generated NavData.
However, each NavData object that you create can only be added to a single Database within a single World. To share the same NavData between multiple Worlds, you must therefore create one NavData object for each World, and set up each of those NavData objects to use the same raw data.
To access the raw data:
To set up each NavData instance, pass the raw data buffer in a call to NavData::LoadFromMemory():
for(KyUInt32 worldIdx = 0; worldIdx < worldCount; worldIdx++) // for each World { Kaim::Ptr<Kaim::NavData> navData = *KY_NEW Kaim::NavData; navData->LoadFromMemory(myDataBuffer); ... // Add your NavData in the World with index worldIdx }
Note: Any changes that you make to the NavData maintained by a single Database at runtime during your game, such as adding TagVolumes or NavGraphs, happen locally within that Database. The static, pre-generated data that is being shared with the other worlds is not affected.
Note: If you choose to use this approach, you must make sure that the raw data remains in memory as long as it is used by any World. Do not release the raw data from memory until you have removed it from all Databases.