Physics collision groups: CREATE at runtime?

Only reason I ask for this, is I’m trying to automate setting the masks of collisionobjects based on their type. I have a module that lets me specify a full mask string for any collision group, and any object that calls “set_masks” on this module, provides its ID and group, will have all the masks set as per the collision matrix settings.

Essentially I’m kind of recreating what Unity already has - it has a matrix of checkboxes for which groups will collide with which groups. Without this, in Defold I need to set the masks property over and over for different groups which have to collide with the other groups that want to collide with it, which is open to human error. This automation is sensible to add - there’s no point in a collision group & mask that doesn’t have a matching reciprocal group mask pair that will collide with it.

Trouble is, I get “Collision group not registered” error when specifying a mask that hasn’t been officially set in any collisionobject settings. So I guess these values are all collected up by the engine and a global collision mask is created from all of those values. If the name never occours in any “group” or “mask” setting, it’s not available to be set with physics.set_mask and I get the error.

The obvious workaround is for me to create a dummy object in the collection that has the group and masks that I want to be available.

Any thoughts on other ways to go about this? What if we could pre-set possible collision masks in the game.project settings under Physics?

1 Like

It feels like this is something which we could improve on but I haven’t looked at the code. The other option is to try out the new b2d API for Box2D which we added in Defold 1.8.0 (in beta right now):

1 Like

Thank you.
For now it looks like if I just add a dummy object with a mask that has every type of group I want, separated by commas, it should take care of the situation.

2 Likes

I had that issue too. That’s how I resolved it.

1 Like

Thank you, good to know I’m not the only one doing it. It seems to be working just fine, and easy enough to do :slight_smile: The dummy object has its own group “dummy” and the mask contains every actual group I want in the scene.