MaterialVariant.BaseMaterial should be readable

As a Roblox developer, it is currently impossible to make a build tool programmatically draw from the available material variants to provide to players in UI because MaterialVariant.BaseMaterial cannot be read from. I require both the material enum value and the material variant name to set a part’s material. Am I missing something?

This property should be readable, I cannot support material variants without the ability to know what material a given material variant is for. These materials are not overrides, I cannot use existing API to get overrides for specific material enum values.

I do not want to have to make some high level organization scheme to accomplish this.

9 Likes

Absolutely foul.

local MS = game:GetService("MaterialService")

module.MATERIALS = {
	["Smooth Plastic"] = {
		material = Enum.Material.SmoothPlastic,
		variant = ""
	};
	-- etc.
}

local variantNameToMaterial = {}
for i,v:MaterialVariant in pairs(MS:GetChildren()) do
	if v:IsA("MaterialVariant") then
		for _,k:EnumItem in pairs(Enum.Material:GetEnumItems()) do
			if MS:GetMaterialVariant(k.Value, v.Name) ~= nil then
				variantNameToMaterial[v.Name] = k.Value
			end
		end
	end
end

for i,v:MaterialVariant in pairs(MS:GetChildren()) do
	if v:IsA("MaterialVariant") and MS:GetBaseMaterialOverride(variantNameToMaterial[v.Name]) == "" then
		module.MATERIALS[v.Name] = {variant = v.Name, material = variantNameToMaterial[v.Name]}
	end
end

I could do with just the last loop instead of making the lookup table if this value was readable.

2 Likes