Get Properties of an Instance

As a Roblox developer it is currently too hard to get the properties related to an Instance.

I’ve seen a few requests for some sort of Instance:GetProperties() implementation, and while I know it’s possible to fetch and parse the API dump in order to find all properties associated with an Instance, it’s not a simple and easy solution.

I’d like to propose Roblox implement some method which will actually return an array of property names associated with an Instance or class.

This differs from previous requests, where Instance:GetProperties() presumably returns a dictionary of { [propertyName]: propertyValue }. In the case of an API like this, nil values would not be featured in the resulting table, and so the property list would be incomplete. Having an API which returns an array of property name strings would mean a complete list of properties is returned, regardless of value.

I would expect a property-retrieval API to run in script context (i.e. properties marked as PluginSecurity would not feature), and I would expect it to return only properties that are read-write, unless read-only is requested specifically.

Concept API

I would expect an API similar to one (or both) of the following to be available:

type GetPropertyListInfo = {
  IncludeDeprecated: boolean,
  IncludeReadOnly: boolean,
  ExcludeWritable: boolean,
}

local DefaultOptions: GetPropertyListInfo = {
  IncludeDeprecated = false,
  IncludeReadOnly = false,
  ExcludeWritable = false,
}

Instance:GetPropertyList(options: GetPropertyListInfo?): { string }
workspace:GetPropertyListOfClass(className: string, options: GetPropertyListInfo?): { string }

Sample code:

local readWriteProps = workspace:GetPropertyListOfClass("Terrain")

local options = GetPropertyListInfo.new()
options.IncludeReadOnly = true
options.ExcludeWritable = true

local readonlyProps = workspace:GetPropertyListOfClass("Terrain", options)
34 Likes

Why would workspace be the namespace for the method? This seems like it would warrant a new service, but then that begs the question whether it’s worth adding one with only one method.

However, having a method for instances directly just limits how you could use it. If I wanted to get the properties of an instance without it being present, I would have to create one and probably destroy it immediately, making it difficult to work with.

I do like the idea of an options argument though, but technically that would be a Params object as Info objects aren’t usually mutable.

1 Like

The code samples and concept implementations here aren’t important. That would be entirely down to Roblox’s dev team and was just to demonstrate what it is I’m looking to get implemented.

Workspace seemed like the most obvious choice, but some sort of reflection service, or anything, would do really.

This is what I’m trying to avoid with these solutions. Currently, to determine if a property is “setable” on an Instance, I’m just throwing it into a pcall and caching the result, but that’s not ideal and doesn’t help me retrieve a list of valid properties either.

Having the method exposed on Instance would be a convenience method for the aforementioned service where the class name would be prefilled since it can be inferred from Instance.ClassName.

In the case of Codify, I need to be able to extract a list of properties for each instance and read their values in order to convert it into code snippets (regardless of whether the value of the property is nil).

I’m currently using the API dump to accomplish this, but I’d love to be able to cut out HTTP requests entirely. I’m sure others have great serialisation or other use cases entirely for these APIs too.

4 Likes

I’ve needed this too many times, especially for UI. Hope some sort of API gets officially implemented.

2 Likes

Yeah it would be really helpful to have this added.

1 Like