Connecting Navmesh from prefabs.

Hi everyone!
I have little problem with Navmesh, first time using this function in Unity. I have in project a little “world” builded from gameobjects with some of it have path when AI can walk, i made second piece of ground also with paths for AI to walk. On both grounds i have NavMesh Surface and both are baked. When i hit play with first block or second blok of ground separately everything works ok but when i try to make function to discover new land and instantiate new block all Agents stuck trying to get to another block from current one they are on. I saw in documentation there is something like NaveMesh Link but when i use it AI just get for moment much speed and sometimes is acting weird so i tried to find on internet solution for this but from what I’ve read this is normal for NavMesh Link. So my question is, how to connect this two separate pieces (NavMesh Surfaces) of ground when one is from start and second is instantiate from prefab?

No one can help? Im struggling with this and trying to find solution but i notice that in Unity 2022.3.11f1 (this is version i actualy use) i can’t even bake mesh in runtime. I found that function in some tutorials from 2019-2021 but i have problem with this. First problem is in new version of NavMesh i can’t get acces to NavMeshSurface from script to bake it in run time so i found on github older AI Navigation (It is big mess in Unity when i found on github files and there is notice that this is now part of Unity but there is no same functionality…) so i tried to remove newer one, instal old one but there is problem to. I can now find obcject with NavMeshSurface using script, i can get component (i see it from inspector) or i can assign it manualy but when i try to use BuildNavMesh(). i get error:

MeshGeneration.GenerateMesh () (at Assets/MeshGeneration.cs:18)
NavSpawnTest.Update () (at Assets/Scripts/NavSpawnTest.cs:15)```

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.AI.Navigation;

public class MeshGeneration : MonoBehaviour
{
    [SerializeField]
    private NavMeshSurface navMeshSurface;

    void Start()
    {
        navMeshSurface = GetComponent<NavMeshSurface>();
    }

    public void GenerateMesh()
    {
        navMeshSurface.BuildNavMesh();
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NavSpawnTest : MonoBehaviour
{
    public GameObject navPlanePrefab;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            Instantiate(navPlanePrefab, new Vector3(8,0,0), Quaternion.identity);
            MeshGeneration meshGeneration = FindObjectOfType<MeshGeneration>();
            meshGeneration.GenerateMesh();
        }
    }
}

Im missing something or doing it wrong? Prefab is spawned ok, but can’t bake this NavMesh. Im forced to use older version of Unity to get this working or is way to do this on 2022 version? Please people, help with this…

well navmesh links need to be placed - cant answer that as theres nothing here… to show what you did or what happened. However, if you have a navmesh on something, and you add chunks of world to it - and try building again, its hard to know what you’re seeing. if you place many navmesh chunks unless you join them no i dont think it doesnt just jump onto the new one. you need the original to extend.

But problem is i can’t bake at runtime becouse of error that im getting (second post). I just have two cubes with NavMeshSurface, and capsule with NavMeshAgent. One cube is from start and second is spawned after some action (for testing purpose is KeyCode.A). Problem is that i have two NavMeshSurface and when i spawn second cube capsule can’t walk from one to another. NavMeshLink is doing jump and is no way for this to connect. After trying to connect them i found that i can bake in runtime but i can’t do it from LTS2022 version.
Must be some way to do this, how it’s done in games generated randomly? Or this function is so basic after 4 years and can’t handle basic thing like connecting Mesh or let me bake it runtime.
I don’t know why access to NavMeshSurface is deleted in never version, this is downgrade istead of upgrade.

So for clarify:
Before i have two cubes with NavMeshSurface i want to connect NavMeshSuraces in this cubes.

Now i have one cube with NavMeshSurface and after spawn another one i want to bake NavMeshSurface again to cover two cubes with NavMesh.

So i can’t extend original NavMesh becouse of error that im getting and can’t join two NavMeshSuraces without weird jump and speed boost.

it shouldnt take much IQ to work out you didnt assign the navMeshSurface an object… after all theres only one variable. so clearly it didnt find the navmesh component…

however, as i said you should only have the original… but hey… you know what you’re doing right?

This “IQ” part you can skip next time… Im not stupid, just read my post again and you can see that in script i have line thath assign navMeshSurface, variable is serialized to see it from inspecor and like i wrote, from inspector i see there is assigned NavMeshSurface to this variable. This is problem.
And second thing like i said is now i have one object (cube) with NavMeshSurface and second object is without it but i can’t bake it.

Next time if you wanna help is good but don’t make people stupid. Is something wrong with 2022LTS version of Unity. I switched to 2021 version and the same scripts that i posted and same objects that i have work like should working at the start. It’s not my first time with Unity and C#, i know how should this work what im wrote.

And for you @bugfinders , this is part of my second post:
“I can now find obcject with NavMeshSurface using script, i can get component (i see it from inspector) or i can assign it manualy but when i try to use BuildNavMesh(). i get error:”

Next time just read and don’t offend people with no reason.

Admin can close this thread, i just use 2021 version of Unity…

Had a similar issue with 2022 LTS, the way I resolved this was to add a NavMeshSurface to the object (and make static and bake) before making it a prefab. Once I instantiate the prefabs at game time, the agents are able to navigate.

hth