#i am generating a maze, and i need
1 messages · Page 1 of 1 (latest)
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
why do you have navMeshBaker.BakeNavMesh(); twice
but they're both run in BeginGame();
might be wrong formatting on discord
sorry for the code screenshot
but one is in restartgame the other in begin game
oh damn my bad you are completely correct
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
wait im kind of lost
BuildNavMesh could be running before Coroutine is done
inside mazeInstance.Generate()
after all the lines are done
call the function to Bake
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?
I guess. Could've also just put the
navMeshBaker.BakeNavMesh();
like i said in Generate() method
did you remove all the static
is it not meant to be static to bake?
no
oh my i might be confusing that with light baking
they're generated at runtime anyway, unity applies static lighting/mesh batching if they are static before the game runs
yes, but thing is there also is the plane which is not 0.1, which is also not getting baked
nefore runtime
it does not spawn at runtime
however i do not bake it
it does not get baked by the code
hmm did you make sure the agent radius is small enough
im compressing a screen recording rn to clarify and show you, might take a while though
no, how do i do this?
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
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
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
this is very good right? the enemy will not go into the walls
okay ill do that
im going to cry from joy
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?
oh my god it works perfectly now im going to kiss you
nicee
i wanted every tile to have a light, and idk if they are
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
okay thank you so much for all the help and advice
np