New Studio Beta: Attributes!

Attributes are now available!


Hey developers,

Over the past year we’ve been working on a new feature called Attributes. Our goal was to provide an efficient way to set and configure parameters for game assets, allowing developers to rapidly iterate and customize key features.

We are excited to announce the launch of the Attributes Studio Beta so that you can try them out and give us feedback before we enable them on production.

How do I enable the beta?

You can enable attributes under the beta features section in studio:

What are Attributes?

Attributes allow you to customize instances with your own data. You can think of them as being similar to properties, but you can create your own for your project.

  • Create, view, edit and delete Attributes within the properties widget
  • Attributes and their values are saved with your place and assets
  • Attributes are replicated with the instance so players can access them immediately
  • Changes to Attributes can be viewed in real-time within the properties widget

They are especially useful when collaborating with other developers or testing. You can surface parameters to team members, so that they can be adjusted without requiring a complete understanding of the underlying code and you can view/edit them in real time while testing.

Use Cases

  • Weapon with custom parameters (see images below)
    • Easily tune a weapon by surfacing parameters such as fire rate, damage, etc.
  • Vehicle tuning
    • Surface parameters such as acceleration and max speed
  • Additional package or asset metadata
    • Include information such as title, description, version

How do you use them?

In Studio

View and Edit Attributes

view

Create a new Attribute

create

Rename and Delete Attributes

renameDelete

From Code

-- Adding a new Attribute:
instance:SetAttribute("MyAttribute", myValue)

-- Getting an Attribute:
local myAttribute = instance:GetAttribute("MyAttribute")

-- Removing an Attribute:
instance:SetAttribute("MyAttribute", nil)

-- Changing an Attribute's value:
instance:SetAttribute("MyAttribute", newValue)

-- Getting all Attributes:
local myAttributes = instance:GetAttributes()

--- Listening to an Attribute changing:
instance:GetAttributeChangedSignal("MyAttribute"):Connect(function ()
    ...
end)

--- Listening to any Attribute changing:
instance.AttributeChanged:Connect(function (attributeName)
    ...
end)

Examples

Lava with configurable damage

local CollectionService = game:GetService("CollectionService")
 
local function lavaAdded(instance)
    instance.Touched:Connect(function (hit)
        local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
        if humanoid then
            humanoid:TakeDamage(instance:GetAttribute("Damage"))
        end
    end)
end
 
CollectionService:GetInstanceAddedSignal("Lava"):Connect(lavaAdded)

Details

Documentation

You can find the complete API documentation on the developer hub:

Types

For the initial release, the following types are supported:

  • string
  • boolean
  • double
  • UDim
  • UDim2
  • BrickColor
  • Color3
  • Vector2
  • Vector3
  • NumberSequence
  • ColorSequence
  • NumberRange
  • Rect

If there are any other types you would like to see supported let us know and please make sure to include clear examples and use cases with your requests.

Name Requirements

When naming attributes, we enforce specific naming conventions for consistency and to help you avoid mistakes. These are:

  • Names must only use alphanumeric characters and underscore
  • No spaces or unique symbols are allowed
  • Strings must be 100 characters or less
  • Names are not allowed to start with RBX (reserved for Roblox)

FAQ

When will the feature go live?

What’s the difference between Attributes and value objects?

Attributes are a part of the instance they are assigned to. You never need to wait for them to replicate or traverse the instance hierarchy to find them. They are there as soon as you need them.

You can view all Attributes on an instance at once, unlike a value object which only supports a single value and therefore you must look at each individually.

In terms of performance, the difference is mostly negligble with a few exceptions:

  • Attributes take up less memory on your device
  • Attributes are ~18x faster to create dynamically
  • Attributes are ~240x faster to delete

As this features continues to evolve you can expect additional behavior to become available which sets them further apart from value objects.

Is there a limit to the number of attributes I can use in my game?

There is no limit to the number of attributes you can use in your game, however there is a limit to the number that can be saved per-instance. That limit is very big so you should not need to worry about it.

Are they replicated from the client to server?

No. Attributes respect filtering rules, the only exception to this is team-create.

Why can’t Attributes be accessed through the index operator?

When designing the API we considered allowing you to index attributes directly:

local myAttribute = instance.MyAttribute

While this may seem convenient there were a number of reasons we decided against this:

Compatability: We could add a new property with the same name as an attribute, this would break your code which depends on the attribute.

Mutability: For mutable data structures we would need to track changes to them. For example assume Vector3 allowed you to change it’s individual components.

  • Should the following code update the attribute?
  • Should the update happen twice? (once for X, once for Y)
local myAttribute = instance.MyAttribute
myAttribute.X = 5
myAttribute.Y = 10

By making you call SetAttribute and GetAttribute we are always working with a copy of your value, and you are explicitly telling us when to update our copy.

Known Issues

Any issues found during beta will be posted here until they are addressed.

  • GetAttribute returns 0 values instead of nil when no value has been assigned
  • Deleting an instance with the attributes context menu open, and then selecting an option on that menu, will cause a crash
  • If you filter for any property and change the value, the attributes section will sometimes appear with no attributes (even if attributes were added to the instance)
  • If you use and then clear the filter, the full list of attributes doesn’t reappear
  • Memory increases with each call to the API
897 Likes

This topic was automatically opened after 8 minutes.

THEY’RE FINALLY HERE


Been waiting over a year for these to officially get enabled, guess I don’t need these settings now haha.
image

also f in chat to valuebases, assume this will supersede them :pensive:.


A small feature request would be the ability to write protect attributes from the client, since they seem to follow the same replication logic as CollectionService

Stop me.
image
(dw im using an elevated plugin, your security does actually work)

147 Likes

THANK YOU for finally releasing this!
It is extremely useful for cleaning up my objects and scripts without values!

wait a second, how many types can we pack in them?!

37 Likes

Yes! This is definitely going to improve my developing experience because I don’t need to use values as often anymore! Thanks for the continued support of improving developer workflow.

13 Likes

Are there plans to allow enforced integer attributes (as opposed to doubles), like IntValues’ .Value properties?

32 Likes

Questions:

  • Is there a limit to how long the string can be? (250k characters)
  • Is there a limit to how many Attributes an instance can have?

Request for data type support:

I would like these Data Types to be supported by Attributes

0 voters

Notes:

  1. It is perfectly fine if Attributes can not support Mixed Table and Array with gaps (although we’d still love for it to be capable)
  2. TweenInfo can’t be sent through the Network (as easily) so this would be a nice alternative


image

GetAttributeChangedSignal


Make sure to fix that link


SetAttribute


I am so happy!


Feel free to take AttributeService I have added 7 functions for more functionality to using Attributes check it out to learn more!

46 Likes

Oh my god! :sob: this is… this is… GREAT!!! THANK YOU!!!

14 Likes

Amazing! What’s the difference between this and simply adding a type of value object inside the object? Is this more efficient?

8 Likes

Woah, this is awesome. I’ve always wondered when these methods would be enabled and anticipated it. (I’ve seen them in the Roblox wiki for so long.) This is going to be a lifesaver with a lot of situations. I can’t wait until this is released fully and I can move to this kind of workflow. Question: Are we going to get more data types? Like tables/objects for instance. haha pun

12 Likes

I was literally waiting so long for this feature that I had given up my hope in hyping them up, and now I am finally glad they’re here. This is going to motivate me big time.

I have a lot of use cases for attributes, including their replacement for ValueObjects. For example: I can use this to set a player’s membership/access status with an attribute over a module which just makes things so much cleaner and accessible in my perspective. I can also use them as sorts of data holders (of course assuming the client can’t propagate changes under any condition). Another use case for them is to customise NPC types/behaviour but still have them all run with a single script.

Really excited to get down to using these. They will help a lot in development.

Any plans to support tables? One of my use cases was to use attributes on a player as a substitute for creating folders of player data. This way, I just need to access their data attribute and then write any changes I want, while the client can check on these changes and update their UI accordingly.

30 Likes

Epic… This will definitely make workflow way more easier and efficient. :open_mouth:

8 Likes

(post withdrawn by author, will be automatically deleted in 1 hour unless flagged)

7 Likes

Less clutter as its suppose to superseed needing Value Objects.

8 Likes

Ah I see. Well, when this gets publicly released, I cannot wait to use this on my future projects. Thanks ROBLOX!

7 Likes

I don’t find this any useful unless I’m trying to avoid value objects.

7 Likes

A much asked request delivered. Thank you and the amazing engineers for pushing this out for us!

8 Likes

This is awesome! I remember first seeing this in the release notes so long ago, and I was wondering when they were coming out, but they’re finally here.

But, I found a bug or intended behavior that should be changed. When getting non-existent attributes such as “Other,” it doesn’t return nil, at least when printing it directly. This can make it extremely hard to debug code since this would be like shoving the mistake under the rug instead of outputting nil.

I expected this to work like FindFirstChild that straight up returns nil inside, without having to store it in a variable.

Some Features

First, I think we should be able to change the data type of the attribute, perhaps, by adding to this drop-down?

image

Second, some datatypes to consider adding are:

  • float - the properties widget adds a slider to float properties, so this should happen as well for attributes
  • Instance - be able to link objects together, e.g. set a frame’s “CloseButton” to an image button whose name can be changed anytime, but the attribute can return the instance itself without having to rely on the name

Lastly, it’d be amazing if the TweenService can support attributes! It is very powerful with properties, but if numerical and color attributes can be tweened, then it’d make this very powerful.

Again, thank you so much!
I do not mind the wait whatsoever, these things are godly!
Keep it up, Roblox! :roblox: :roblox_light:

42 Likes

(post deleted by author)

9 Likes

This is amazing! It’s a shame that it doesn’t seem to support tables, but that’s a fairly minor thing anyways. The main thing I’m disappointed about is that the attributes can’t be indexed like properties. You have to use a function to access it.

Also, I noticed that when entering a negative number into a NumberSequence attribute, it shows this:
https://i.gyazo.com/a3ea5d5a3d6731ebcdd0cbb5bdea68f3.gif

11 Likes