4

My question refers to NavigationMeshes, I have prepared a Map Generator that is grid-based. I can generate a map that consists of cubes that are divided into walls and floor.

after generating this i can keep it as a prefab, later in the navigation menu I can bake the meshes, but what comes next is that I would like to save it as a prefab with already baked navmeshes. When i do that and remove map from scene, it dissaperas but baked mesh is still there. To put map on the scene again in another place i have to bake again. The main idea was to generate "x" levels with baked meshes and later just instantiate them depending on what level i want. Is that possible? Thanks for your time.

Edited: After baking some exmaple navmesh a folder called same as the scene i am working on appeared and there's navmesh file inside. Now here goes my edited question. Can I bake few different navmeshes for each different map and later after loading such map use the proper navmesh in code, so they cooperate well?

Power
  • 141
  • 1
  • 11

1 Answers1

4

after generating this i can keep it as a prefab, later in the navigation menu I can bake the meshes, but what comes next is that I would like to save it as a prefab with already baked navmeshes

Unfortunately it's not possible. NavMesh are saved by scene, and currently you can't explicitly reference/instantiate them.

On the other hand, it should be possible to exploit additive scene loading to use several lightmaps stored into different scenes. Have a look at Application.LoadLevelAdditive.

Instead of saving a navmesh to a prefab, you can use a dedicated (eventually empty )scene, and load it additively on demand.

Heisenbug
  • 38,762
  • 28
  • 132
  • 190
  • I have already met this solution somewhere before, but i have also noticed that there were some problems while trying to use LoadLevelAdditive, namely NavMesh of the previously saved scene wasnt loading. Could Application.LoadLevel work instead? – Power Apr 17 '15 at 13:01
  • Which version of unity are you using? It should work. LoadLevel not additive will replace the current loaded navmesh with the one on the loaded level, so it's not what your looking for I guess. If load additive don't work properly with navmesh (I don't remember if it's a new feature of 5.x) post the relevant code so I can have look, or eventually submit a bug report. – Heisenbug Apr 17 '15 at 13:31
  • I guess this is exactly what am looking for. I have a game where i can choose which level do i want to play. A border with shown levels. To start next level i have to pass the previous one, but! but i can alwyas get back to the older one's(e.g. i wanna get better score). The play mode is very similar to the angry birds. BTW i am using unity 5.0.4f pro. It brings next question. The fact is that LoadLevel will work, but do i have to get rid of the current scene before loading the next one? – Power Apr 17 '15 at 13:50
  • 1
    Load level destroy the current scene (with the current navmesh) and load the new one (with the relative navmesh if any) in a snychronous way. If each level has it's own navmesh that you can stick with loadlevel or loadlevelasync – Heisenbug Apr 20 '15 at 10:39
  • Creating a dedicated scene for each level is a best way in my case. Thanks for very usefull and helpfull comments. – Power Apr 20 '15 at 11:35