- Home /
How to generate a NavMesh only with colliders?
Hi,
We are experiencing some trouble with NavMeshes. We are developing a 2D sprite-based sidescrolling game, and we can't generate any NavMesh only with the colliders of the sprites, we have to add physical 3D meshed objecs in order to get the NavMesh created. However, this is absurd since we do not need any 3D modelled object or ground in a sprite game.
Is there any way to achieve this? Thanks.
Answer by Frallis · Mar 17, 2017 at 10:02 PM
Its possible to keep the mesh renderer and set materials to 0
Great answer, set $$anonymous$$aterials > Size to 0, and don't just delete the one that exists, or it will be a pink object. :)
Answer by permanentrecords · Sep 27, 2013 at 06:03 PM
I ran into this issue today and came up with an answer. It works, so I am very happy. I create cubes where I want the navmesh, or add a mesh renderer to the colliders I have and set them to a transparent material so that I can tell when it is on or off. I then threw them all in an empty gameobject just to keep them together, and then baked the navmesh. When that was done, I disabled the mesh renderers - they went away leaving the navmesh - and colliders - intact.
So I am not alone experiencing this issue. It is quite annoying, as in my case I need to keep my colliders and my navmesh object separated. And each time I need to make a change to my navmesh I need to turn the mesh renderer on again, it's quite messy in my opinion
Answer by alior · Mar 06, 2015 at 04:48 PM
You can create this with meshes. You should add the script like the following to the objects that you don't wanna see after game starts:
class SomeScriptName
{
void Awake()
{
gameObject.SetActive(false);
}
};
Now you can bake you navMesh. The mesh will not change while the objects are enabled. After game starts your objects dissables and you dont have it on your scene. After you press stop objects will be enabled and you can modify it if you want :) (Another on advice: don't make them fully static. Just mark as walkable with NavMesh window. Disabling static object can cause big overhead)
Answer by baixiaobest · Jul 03, 2016 at 12:41 PM
My way of solving this is instead of setting the object to transparent material, I set it to invisible using custom invisible shader. That way you can enable the mesh renderer and you will not see the object.
Shader "Custom/Invisible" {
Properties {
}
SubShader {
Tags { "Queue" = "Transparent" }
Pass{
Tags{"LightMode" = "ForwardBase"}
ZWrite off
Blend Zero DstAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct inputVertex{
float4 vertex : POSITION;
};
struct outputVertex{
float4 pos : SV_POSITION;
};
outputVertex vert(inputVertex v){
outputVertex o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
float4 frag(outputVertex i) : COLOR
{
return float4(0,0,0,0);
}
ENDCG
}
Pass{
Tags{"LightMode" = "ForwardAdd"}
ZWrite off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct inputVertex{
float4 vertex : POSITION;
};
struct outputVertex{
float4 pos : SV_POSITION;
};
outputVertex vert(inputVertex v){
outputVertex o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
float4 frag(outputVertex i) : COLOR
{
return float4(0,0,0,0);
}
ENDCG
}
}
FallBack "Diffuse"
}
You need to create a new material with this shader, then attach the material to the object. Then, you can bake this invisible object into navmesh.
Answer by LeopardX · Jun 02, 2021 at 02:03 AM
Keep the mesh render on, and just give the object a trasparent material set to fade.