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.

Its possible to keep the mesh renderer and set materials to 0

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.

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 :slight_smile:
(Another on advice: don’t make them fully static. Just mark as walkable with NavMesh window. Disabling static object can cause big overhead)

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.

Keep the mesh render on, and just give the object a trasparent material set to fade.