Undesirable PhysicsService:CreateCollisionGroup() behaviour (Errors for existing collision groups)

As a Roblox developer, it is currently too hard to rely on PhysicsService:CreateCollisionGroup() in my code due to it erroring if being called more than once for the same group name.

If Roblox is able to address this issue, it would improve my development experience because it would allow for cleaner collision group code in cases where a collision group is created at runtime and used more than once. It’s unnecessarily difficult to use collision groups in multiple scripts which run in parallel.

I propose based on my use case that either the behaviour of :CreateCollisionGroup() is changed so that it returns existing collision group ids rather than erroring. The impact that this could potentially have on existing code would be very small.

7 Likes

In my opinion, a better solution would be leaving the API as it is, but making :CreateCollisionGroup() act like :GetCollisionGroupId() when the group already exists.

I believe the reason behind this implementation was to avoid hard to debug errors due to group name typos. That’s nice and all, but right now I have this ugly one liner in each script that works with collision groups:

local id = ser:GetCollisionGroupId("name") or ser:CreateCollisionGroup("name")
3 Likes

I definitely agree, and I’ve made an edit to my request. Before I didn’t really consider how a behaviour change could effect code. Thinking about it more, the only cases where a behaviour change would cause issues is where a script is actually intending for an error to be produced, for example, to check if the collision group exists or not (which I think would be a questionable use)

There is also another reason why introducing a new API would be worse than changing an existing one, especially in this case, which is development resources. Changing the API is significantly easier than adding a new one and having to do all of the work ensuring it works and maintaining both in the future. It’s really just less to keep track of.

(Also I’m stealing that one liner because its way better than wrapping it in a pcall like I have been :grimacing:)

2 Likes