NavMesh WalkableMask

Hi there,

I couldn’t find too much info on the walkable mask and the manual is quite thin about this subject.

I set up doors with different NAvNesh layers, but I can’t find a match between the layer index and the value of the walkableMask.

So my question is what is the value of the walkableMask parameter referencing to ? Is it a layer number ? but there are Built in layers and user layers.

For example in the user layer 1 I have setup door 1 and user layer 2 contains door2
How do I activate / deactivate them in runtime?

Please shed some light !
Thank you

Jean from the Playmaker forum answered this in depth:

OK; let’s do some binary maths!!!

Binary is a very powerful thing, you only have 0 and 1, and as you read a long binary number you need to think this way, lets’ take an example

– read the binary from right to left, each binary entry being indexes (n) with its integer equivalent being 2^n, n starting at 0, so the first slot on the right is indexed 0, not 1.

binary slots : x | x | x | x
integer value: 8 | 4 | 2 | 1

100 binary mean 4 as int (4+0+0)
101 means 5 (4+0+1)

Hopefully that make sense. So to translate this to the navmesh layers in Unity

nothing - 0
everything -1
layer 0 - 1 ( built in layer 0)
layer 1 - 2 ( built in layer 1)
layer 2 - 4 ( built in layer 2)
layer 3 - 8 ( user layer 0)
layer 4 - 16 ( user layer 1)
layer 5 - 32 ( user layer 2)
layer 6 - 64 ( user layer 3)
layer 7 - 128 ( user layer 4)

– if you want to only have layer 3 ( user layer 0), the mask is 8, in binary, we would write 1000
– if you want layer 3 AND layer 0, the mask is 8+1=9, in binary: 1001

to find out from the mask integer what layers are defined, it’s bit a more complicated if you are not using binary math operators:
so we have 9:
the question to ask is:
– what’s the biggest multiple of two we can fit in 9, its 8, meaning we include layer 3,
– we substract layer 3 we are now left with 1 (9-8)
– what’s the biggest multiple of two we can fit in 1, it’s 1, meaning we include layer 0

Does that make sense? this way, with a single int, you can define a mask for any layers without risking confusion. 9 can only mean you include layer 3 and layer 0, reading the binary from right to left, 1001, we can find out visualy, that index 0 and 3 are set to 1, so layer 0 and layer 3 are included.

If you don’t understand this, don’t worry, get back to this and document yourself on the net and find examples to work with binary, it will start making sense if you actually use it and find real world examples.



I suppose Everything is not exactly 1…