Multiple layer masks


#1

Hello all!

I’ve just started myself off with Unity and needed some pathfinding for my little big project.

What I’m trying to do is use 2 grid graphs, both the same size, position etc identical other than using different masking layers.

One is for Structures (Walls and Floors) and the other for Objects (Machinery and Doors etc) which I’m also using for constructable doors which can be locked and well… behave like you’d expect from a door. Box collider on/off when opened and closed.

I have a seeker set to path to another room accessible through a locked door or an open hallway. It has both graphs set to use but my problem is that it always attempts to go through the locked door or when the graphs are the other way around it just goes through the walls. Ideally I want it to only attempt to go through the door if it has the correct key to unlock it and if not, try an alternate route.

Is there a way to set a graph grid to use multiple layer masks? I’m probably just being stubborn or stupid and should use another method…


#2

Hi

I’m not sure what you are saying. Are you saying that you have two graphs, but they contain different obstacles? Why not one graph which has all the obstacles?


#3

The issue is that I have these obstacles on different layers in the editor and the grid graph only allows me to select a single layer as the mask. I’m starting to think I should have just used tags and drawing order rather than using layers.


#4

Hi

It should allow you to select multiple layers (assuming you are talking about the height testing/collision testing layer masks). Are you sure it does not allow you to do that?


#5

I don’t think so, I’m not at my desktop to double check but it’d be perfect if it does and I was just silly to miss it. I’m using it with 2D collision and general 2D settings for the grid graph if that makes a difference but as far as I knew I could only use a single layer mask to map the grid with per graph grid.


#6

Okay. Do double check that, because it really should. If not, it might be some weird incompatibility with a new version of Unity perhaps?


#7

Looking at the docs @ Graph Collision it doesn’t look like it handles it with just Public LayerMask mask


#8

Huh.
Both the masks are indeed LayerMasks, here is a screenshot from that page you linked:

image


#9

I was being stupid, you can add more than one. I guess it’s a bitmask.

Everything working perfectly now and moving forward again! Thank you!