ObjectReference type

I recently found out Roblox added packages and instance attributes, which is a big leap in features a game engine should have, much like Unity’s prefabs or Unreal Engine’s asset pipeline. What I’d really like to see next is a way to have instance attributes refer directly to an object, which currently isn’t supported.

ObjectValue has existed for as long as I can remember, but it’s still not quite right - really there should be a data type rather than a dedicated instance with a property that references another instance. Instance attributes could then support this data type, and scripts could be massively simplified by accessing direct references followed by a method like GetObject() or WaitForObject() rather than using hardcoded chains of FindFirstChild and WaitForChild. This new pattern of using instance attributes with object references would be a major improvement to code cleanliness.

4 Likes

Sorry, I don’t quite follow; can you give a code sample of what your suggestion could look like in practice (if possible)?

local newDriver = game:GetService('Players').Player1
carModel:SetAttribute('Driver', newDriver)

-- different script
local driverPlayer = carModel:GetAttribute('Driver')

Ah, ok. I’ve actually had this thought before, but in the form of something like Instance.fromUniqueId() since Instances have a UniqueId attached them:

local part = Instance.new("Part")
local uniqueId = part.UniqueId -- This property is inaccessible, but it's just an example
Object:SetAttribute("PartReference", uniqueId)

-- later on
local referencedPart = Instance.fromUniqueId(Object:GetAttribute("PartReference"))

A new datatype would be better to have though for usability.

2 Likes

Feature requests should focus on problems and use cases, not solutions. At the root of this request, you’re just asking for instance attributes.

1 Like