BUG: Collision mask functionality breaks down when used with non-continuous objects.

ColMaskBug.blend (538 KB)
The .blend file has two scenes that should be more or less explain itself.

There are two scenes where the geometry is identical, they comprise of 2 blue walls that have a collision mask that is different from the one used by the player. As a result, you can move the player through the walls.

However, that only works well when each blue wall is a separate object, when they’re separate objects things work as expected.

Now to the scene labeled ‘Masks broken’, in that scene the blue walls are part of a single object, however, you can see that the player is colliding with the walls now as if the collision layers don’t exist. I don’t know if the bug is something on the BGE side or something for the Bullet devs. to fix but I could see this causing a bit of head scratching in cases where objects are made of separate parts.

In short, things will work as expected only if it’s continuous (every face having a connection that can lead to all the others) and not broken into two or more different parts, the workaround right now is simply P > ‘loose parts’, but it’d be good if it can be fixed.


Ah! This is a similar problem that I am trying to solve. Currently, the implementation of collision masks is built on top of the existing masks in Bullet. In other words, it doesn’t interface with bullet directly. Bullet works something like this:

  • Bullet checks the AABB intersection of the two objects. If they intersect, it calls a “needsBroadphaseCollision” callback before adding to a cache, then moves to a different collision callback.
  • During this check, Daniel and Mitchell implemented the Blender collision masks, which are separate from the Bullet masks. To check for a collision between objects, it calls CheckCollision (KX_GameObject->CheckCollision) which returns the intersection between mask and group, and it calls this for each object in the collision pair.
  • The outcome of these two callbacks overrides the outcome of the bullet filters, (which are bullet’s own mask and groups).
  • If the collision is deemed True, it then adds the objects to the cache.

My problem for the patch is that changing the masks doesn’t take effect if a collision already occurs. This is because by this point the objects have been added to the broadphase cache, thus the CheckCollision method is no longer checked. To solve this, I believe I need to implement another callback, nearCollision or something to that name (it’s mentioned in the Bullet API) to continue to check the intersection.
I have some idea of where to start, but I need to learn a little more (hopefully with the support of Benoit) after initially consulting with Mitchell.

The reason that this is similar to your problem is mentioned in the source;

    //Note that this is called during scene    
    // conversion, so we can't assume the KX_GameObject instances exist. This
    // may make some objects erroneously collide on the first frame, but the
    // alternative is to have them erroneously miss.

Essentially, after checking the bullet filters it checks the user masks (from Blender). Yet as the GameObjects do not exist, they cannot influence the very first collision check, thus any objects with intersecting bounding boxes on startup will collide (the same problem that may be fixed by a following callback). Hence, to solve your issue, isolate the bullet from the bounding box of the two planes.

In hindsight, It may be better to deny the collision if the two objects do not have masks yet (do not exist) for the implications of that would only last one physics tick. However, in solving this true issue in a later callback, it would really make little difference, thus it would only be a temporary fix. (assuming that this is called throughout the intersection of the bounds, otherwise its the same problem in reverse)

Temporary fix based upon assumption:

//(line 2286)
    return false;

…double post…

Hi AceDragon, just confirm the same behaviour (2.65)

i noticed other detail ,the collision mask not work also when the “ghost wall” have all “faces continuous” (as a cube)
but the shape is a bit different , see below (very strange…mah)


ColMaskBug2.blend (92.5 KB)

This is a result of the bounds intersection(see above)

amazing agoose77! you re expert of Bullet ? by change you have written a part of it ? (someone have written it!)
i consider Bullet the best piece of BGE!

[translation original] incredibile agoose77 , sei un esperto di Bullet codice? lo hai scritto tu per caso? (qualcuno lo deve avere scritto!)
io considero Bullet il migliore pezzo di codice di BGE!

Thanks Marco, And thanks again for using Italian as well - I did some Spanish and I still do French which makes it slightly easier to understand bits I’m not sure about!

I had to learn about Bullet so I could find why my patch didn’t work. It actually turned out to be the same problem! For now you will have to accept the problem until the patch is complete.

" the workaround right now is simply P > ‘loose parts’, but it’d be good if it can be fixed."

another workaround is spawn the cube from an empty …

also in this way all work correctly


ColMaskBug3.blend (91 KB)

Great to see that someone already knows what is going on the source code that breaks this in various situations and has an idea on how it can be fixed.

MarcoIT: I never thought the issue would’ve been intersecting bounding boxes at start, that means I would only have to separate a larger object (like invisible walls), into parts that would remove starting intersections with the player, which might make things a bit easier for the situation I’m looking at.

yes avoid the bound box (at start position) seems the workaround more light .

( it took me a bit of time that this thing was already explained by agoose77 :stuck_out_tongue: )