MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / SaveNavMesh

Method SaveNavMesh

Source/Engine/Navigation/NavMesh.cpp:25–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25void NavMesh::SaveNavMesh()
26{
27#if COMPILE_WITH_ASSETS_IMPORTER
28 PROFILE_MEM(NavigationMesh);
29
30 // Skip if scene is missing
31 const auto scene = GetScene();
32 if (!scene)
33 return;
34
35#if USE_EDITOR
36 // Skip if game is running in editor (eg. game scripts update dynamic navmesh)
37 if (Editor::IsPlayMode)
38 return;
39#endif
40
41 // Clear flag
42 IsDataDirty = false;
43
44 // Check if has no navmesh data generated (someone could just remove navmesh volumes or generate for empty scene)
45 if (Data.Tiles.IsEmpty())
46 {
47 DataAsset = nullptr;
48 return;
49 }
50
51 // Prepare
52 Guid assetId = DataAsset.GetID();
53 if (!assetId.IsValid())
54 assetId = Guid::New();
55 const String assetPath = scene->GetDataFolderPath() / TEXT("NavMesh") + Properties.Name + ASSET_FILES_EXTENSION_WITH_DOT;
56
57 // Generate navmesh tiles data
58 const int32 streamInitialCapacity = Math::RoundUpToPowerOf2((Data.Tiles.Count() + 1) * 1024);
59 MemoryWriteStream stream(streamInitialCapacity);
60 Data.Save(stream);
61 BytesContainer bytesContainer;
62 bytesContainer.Link(ToSpan(stream));
63
64 // Save asset to file
65 if (AssetsImportingManager::Create(AssetsImportingManager::CreateRawDataTag, assetPath, assetId, (void*)&bytesContainer))
66 {
67 LOG(Warning, "Failed to save navmesh tiles data to file.");
68 return;
69 }
70
71 // Link the created asset
72 DataAsset = assetId;
73
74#endif
75}
76
77void NavMesh::ClearData()
78{

Callers

nothing calls this directly

Calls 12

GetSceneFunction · 0.85
GetIDMethod · 0.80
GetDataFolderPathMethod · 0.80
NewFunction · 0.50
RoundUpToPowerOf2Function · 0.50
ToSpanFunction · 0.50
CreateFunction · 0.50
IsEmptyMethod · 0.45
IsValidMethod · 0.45
CountMethod · 0.45
SaveMethod · 0.45
LinkMethod · 0.45

Tested by

no test coverage detected