Bulk setter for Attributes

I would like a method that allows a developer to set multiple Attributes with a single call.

The current developer solution looks like this:

local function SetAttributes(instance, attributes)
	assert(typeof(instance) == "Instance")
	assert(typeof(attributes) == "table")
	
	for key, value in pairs(attributes) do
		instance:SetAttribute(key, value)
	end
end

Presumably, creating a loop of assertions and Set calls is leaving a lot of performance on the table.

Adding Instance:SetAttributes(dict) would be very handy in situations where a plethora of Attributes are applied to an Instance at the end of a process that might run each heartbeat or physics step, such as a car’s engine data.

41 Likes

Slowly drowning into insanity dealing with attributes in an instance based inventory system. We already have GetAttribute and GetAttributes, but only SetAttribute without SetAttributes, which perplexes me. It seems like a simple addition with a lot of benefit and without any API collision, and yet…

3 Likes

Adding this would remove so much repetitive code, still waiting for when this gets added :pray:

1 Like