#i am generating a maze, and i need

1 messages · Page 1 of 1 (latest)

empty atlas
#

this will be better

#

what i have done is remove the baking of the plane before, and i added in an empty game object with this script : ```using UnityEngine;
using UnityEngine.AI;
using Unity.AI.Navigation;

public class NavMeshBake : MonoBehaviour
{
public NavMeshSurface surface; // Reference to the NavMeshSurface component

// Call this method after spawning your walls
public void BakeNavMesh()
{
    if (surface != null)
    {
        surface.BuildNavMesh();
        Debug.Log("NavMesh baked successfully!");
    }
    else
    {
        Debug.LogError("NavMeshSurface reference is missing!");
    }
}

}```

#

after which i added in this into the main manager class ```using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour
{

public Maze mazePrefab;

private Maze mazeInstance;

public NavMeshBake navMeshBaker;

private void Start()
{
    BeginGame();
}

private void Update()
{
    if (Input.GetKeyDown(KeyCode.Y))
    {
        RestartGame();
    }
}

private void BeginGame()
{
    mazeInstance = Instantiate(mazePrefab) as Maze;
    StartCoroutine(mazeInstance.Generate());
    navMeshBaker.BakeNavMesh();
}

private void RestartGame()
{
    StopAllCoroutines();
    Destroy(mazeInstance.gameObject);
    BeginGame();
    navMeshBaker.BakeNavMesh();
}

}```

#

which calls navMeshBaker.BakeNavMesh

#

after the maze is generated

#

however, no mesh is created

#

this means that there is no problem with the walls/small planes, as even the large plane which can be baked before isnt baking

#

absolutely no clue whats going on

visual kite
#

why do you have navMeshBaker.BakeNavMesh(); twice

empty atlas
#

If i reset the maze

#

the second one is if the maze gets destroyed and built again

visual kite
#

but they're both run in BeginGame();

empty atlas
#

might be wrong formatting on discord

#

sorry for the code screenshot

#

but one is in restartgame the other in begin game

visual kite
#

Restart is running BeginGame

#

which already runs BuildNavMesh

empty atlas
#

oh damn my bad you are completely correct

visual kite
#

might want to add a delay to that build

#

esp if its generating inside a coroutine

#

ideally you dont use timer at all but an Event or Method you call directly when its done generating

#

Ie after all the lines in IEnumerator are done

#

Coroutine doesnt wait for anything else

#

once its ran its still running while other lines run

empty atlas
#

wait im kind of lost

visual kite
#

BuildNavMesh could be running before Coroutine is done

empty atlas
#

oh okay

#

and how to do that without a timer?

visual kite
#

inside mazeInstance.Generate()

#

after all the lines are done

#

call the function to Bake

empty atlas
#

is that not what i am doing?

#

im really sorry if this is simple but im really new

#
using System.Collections;

public class GameManager : MonoBehaviour
{
    public Maze mazePrefab;
    private Maze mazeInstance;

    public NavMeshBake navMeshBaker;

    private void Start()
    {
        BeginGame();
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Y))
        {
            RestartGame();
        }
    }

    private void BeginGame()
    {
        StartCoroutine(StartGameRoutine());
    }

    private IEnumerator StartGameRoutine()
    {
        mazeInstance = Instantiate(mazePrefab) as Maze;

        yield return StartCoroutine(mazeInstance.Generate());

        navMeshBaker.BakeNavMesh();
    }

    private void RestartGame()
    {
        StopAllCoroutines();
        Destroy(mazeInstance.gameObject);
        BeginGame();
    }
}
#

like this?

visual kite
#

I guess. Could've also just put the
navMeshBaker.BakeNavMesh();
like i said in Generate() method

empty atlas
#

oh okay i didnt understand it well

#

anyways the mesh is still not working

visual kite
#

did you remove all the static

empty atlas
#

is it not meant to be static to bake?

visual kite
#

no

empty atlas
#

oh my i might be confusing that with light baking

visual kite
#

they're generated at runtime anyway, unity applies static lighting/mesh batching if they are static before the game runs

empty atlas
#

oh okay, i have removed all the static now

#

still the same

#

what do i do?

visual kite
#

thats most of what i thought it could be

#

are all the floor tiles still 0.1?

empty atlas
#

yes, but thing is there also is the plane which is not 0.1, which is also not getting baked

visual kite
#

which plane

#

and at runtime or before

empty atlas
#

nefore runtime

#

it does not spawn at runtime

#

however i do not bake it

#

it does not get baked by the code

visual kite
#

hmm did you make sure the agent radius is small enough

empty atlas
#

im compressing a screen recording rn to clarify and show you, might take a while though

empty atlas
visual kite
#

on the navmesh surface it says Agent Type

#

click it and do Open Agent Settings

#

try something really small like 0.2f radius

#

or maybe 0.1

empty atlas
#

do i keep height at 2?

#

Okay, so if i kept height at 2 nothing baked, however, if i changed it to 0.4 this did

#

i suppose we are getting somewhere as something baked, but for some reason it also took the sphere into account, and baked it aswell, and it may be a bit hard to see but the capsule(enemy) walked on top of the sphere

visual kite
#

okay getting closer

#

What I would do is
either put all static geomtry into its own Layer (be aware if you have anything using Default Layer)

#

then only bake for that Layer in the Surface

empty atlas
#

this is very good right? the enemy will not go into the walls

visual kite
#

correct that look right now

#

phew

#

radius was too big ig

empty atlas
#

im going to cry from joy

visual kite
#

makes sense now since they tiles are actually tiny 0.1

#

I dont usually work with such small sizes so it threw me off a bit didnt think of the agent radius till later 😅

#

Also why are there so many lights are those realtime lights?

empty atlas
#

oh my god it works perfectly now im going to kiss you

visual kite
#

UnityChanCelebrate nicee

empty atlas
visual kite
#

Oh alright. Well be careful with realtime lights they are not cheap heh

#

and baking is usually not an option with runtime generated level

#

Unity wants to do all that crap before the simulation runs

empty atlas
#

okay thank you so much for all the help and advice

visual kite
#

np

empty atlas
#

you quite literally are a lifesaver

#

have a nice rest of the day