CollectionService API should be directly usable via instances

As a Roblox developer, it is currently too hard to work with CollectionService tags. It’s an extremely powerful tool but the implementation is somewhat awkward. Right now we have to use the service to check an instance, instead of directly calling a function of the instance itself.

Current usage:

CollectionService:AddTag(Instance, Tag)
CollectionService:HasTag(Instance, Tag)
CollectionService:RemoveTag(Instance, Tag)
CollectionService:GetTags(Instance)

Desired usage:

Instance:AddTag(Tag)
Instance:HasTag(Tag)
Instance:RemoveTag(Tag)
Instance:GetTags()

I mistakenly write Instance:HasTag() all the time because it just feels more natural. Having the support for it would remove that friction from my workflow.

33 Likes

Big support, I would love an instance-level API for tags. It feels completely reasonable as well considering tags are serialised on instances like attributes. I feel really silly writing out any of the CollectionService methods that require an instance argument and would much rather prefer if I could just directly query the tags from the instances themselves.

PhysicsService was updated so that the API was based more on an instance-level instead via the property and deprecation of some instance APIs. Attributes are already serialised on instances and have a full suite for working with them. Instance-level tags API would feel much more intuitive.

2 Likes

This would make job much easier if we would be able to access it’s API through instance.
This would also bring versatility to collection service. For example, you could get tagged children or descendants while limiting it only to instance, listening if children/descendant with that tag was added/removed.
That’s a really big support.

1 Like

You can already do this with attributes.

Instance:GetAttribute(tag)
Instance:SetAttribute(tag, tag_name)
Instance:GetAttributes()
instance:SetAttribute(tag, nil)

Feature Request counterpart:

Instance:HasTag(tag)
Instance:AddTag(tag)
Instance:GetTags()
instance:RemoveTag(tag)

This feature request is just going to add another “Add Attribute”-like button in the property widget when you select an instance.

1 Like

It doesn’t make sense to bloat the instance of more API than there already is, as @SkyWarrior805 said we could easily use attributes.

This is not correct, you cannot get all tagged items when using attributes

7 Likes

Attributes don’t have the important functionality of CollectionService such as GetTagged and GetInstanceAddedSignal.

Also, an “Add Attribute”-like button was not part of this feature request.

1 Like

I suggested this a few years ago, but this is a much more to-the-point description.

My API diff tool picked up this change on zIntegration:

Added Function void Instance:AddTag(string tag)
Added Function Array Instance:GetTags() {🧬Safe}
Added Function bool Instance:HasTag(string tag) {🧬Safe}
Added Function void Instance:RemoveTag(string tag)

It should be arriving in the next week or two!

5 Likes

Yep! Hoping to start rolling this out next week–it comes with some internal refactors to CollectionService so fingers crossed.

15 Likes

Just to keep you posted, I silently turned this on and we found a bug that broke the behavior of CollectionService:GetTags(nil). Will be getting a fix out soon for next week to try again :slight_smile:

7 Likes

Any updates on this new feature?

We’ve been hitting an unusual bunch of snags in being able to turn on features recently unfortunately :frowning:

I think they are all cleared up now, so I will ste a reminder to myself for Monday!

5 Likes

Hey folks, this has been live for a bit and hasn’t been causing issues, so it should be safe to use now :partying_face: (though I may still need to write documentation!)

6 Likes

Yeyyy! finally! thanks for this!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.