How do I support MaterialVarient in code?

Hello, I’m not much of a programmer, but I’m trying to add support for the new MaterialVariant in my game’s code, I imagine this wouldn’t be difficult to add since my game already supports the default materials.

But I don’t know what code I need to write or change to support the MaterialVariant, here’s how the block of code looks:

image

image

If anyone could help me out I would greatly appreciate it!

Thank you!

The valid material enumeration items can be located here.

https://developer.roblox.com/en-us/api-reference/enum/Material

3 Likes

How do I get this to apply to for the new MaterialService / MaterialVariant? I see that the Enum I’m using only grabs the list of default Roblox Materials, but none of the MaterialService (Custom Materials) that I’ve added.

The MaterialVariant property takes the name of a MaterialVariant instance instead of the Material enum

ex. BasePart.MaterialVariant = "TestMaterial"

1 Like

Ahh okay! Sorry I’m not a programmer so I don’t fully understand how all the types and classes are setup, so in this case, I’m trying to setup code in two places, one where it allows me to setup the structure of code so I can call on any new material I make and apply it to the skin, here’s how it looks:

local ISkinnableProps = Types.Interface {
	Material = Types.Optional (Types.EnumItem (Enum.Material)),

	Transparency = Types.Optional 'number',
	Reflectance = Types.Optional 'number',
	Color = Types.Optional 'Color3',
	Texture = Types.Optional(Types.Interface {
		Image = 'string',
		UVScale = 'number',
	}),
}

This code allows these properties to be edited by the skin


registerAvatarContent(
	ARMOR_SKIN_SLOTS,
	'dark_indigo_skin',
	TEAM_AFFILIATIONS.Civilian,
	AvatarContentArmorSkin.new {
		SkinnablePrimaryColor = {
			Material = Enum.Material.Foil,
			Color = Color3.fromRGB(0, 32, 96),
		},
		SkinnableSecondaryColor = {
			Material = Enum.Material.Foil,
			Color = Color3.fromRGB(30, 11, 50),
		},
		SkinnableTertiaryColor = {
			Material = Enum.Material.Foil,
			Color = Color3.fromRGB(30, 11, 50),
		},
		SkinnableGlass = {
			Material = Enum.Material.Foil,
			Color = Color3.fromRGB(19, 6, 43)
		},
		SkinnableExtraColor = {
			Material = Enum.Material.Foil,
			Color = Color3.fromRGB(107, 50, 124),
		},
		SkinnableSkeleton = {
			Material = Enum.Material.Foil,
			Color = Color3.fromRGB(107, 50, 124),
		},
		SkinnableVisor = {
			Material = Enum.Material.Foil,
			Color = Color3.fromRGB(107, 50, 124),
		},
		SkinnableNeon = {
			Color = Color3.fromRGB(170, 85, 255),
		},
		SkinnableForcefield = {
			Color = Color3.fromRGB(85, 0, 255),
		},
		SkinnableTubing = {
			Material = Enum.Material.Foil,
			Color = Color3.fromRGB(27, 42, 53)
		},
	}
	:SetDisplayName("Dark Indigo Skin")
	:GiveCategoryTags {'ArmorSkin', 'AureumPurchasable' }
	:SetPremiumValue(250)
	:SetRarity(RarityConstants.RarityEnum.Epic)
)

Here’s an example how one of the skins are setup, I’m unsure how I would add MaterialVarient to this code since it doesn’t use Enum, from what you explained I would just do BasePart.MaterialVariant =
“MaterialName”?

In your case you should just specify that the type is a string (which I’m assuming would just be Types.Optional 'string' ), I should have mentioned that earlier

1 Like

Thank you! I changed the code here:
image

Now how would I call on a specific skin from the MaterialService?
image

I imagine this isn’t the right structure for here?

… yeah strings don’t work like that. Instead of string.Carpet it should be Carpet

Does this work in real servers yet? MaterialService

Hmm I seem to get unknown global:
image

It’s available on Desktop right now

Oh right, I completely forgot you have to put " around it, so it should be "Carpet", my bad

1 Like

Yeah “Carpet”, or Enum.Material.Carpet will do. If it’s some kinda number like the dude above said then maybe try setting it to a random number like 1 and see what happens.

Nvm I don’t think Enum supports Carpet it appears tried it just now

It no longer errors, but it also doesn’t seem to be applying the skin?

The MaterialVariant has to be in MaterialService

Yep, It’s in MaterialService:

Are you applying the MaterialVariant anywhere?

Do you mean outside of the code?

Obviously not, is the MaterialVariant being applied anywhere when the prop gets added by a script?

I’ve only added the MaterialVariant in two areas of the code, the skin is applied when player equips the skin through our character editor, it then applies it to the armor model.


It applies all the other colors and materials besides the MaterialVariants, there doesn’t seem to be any errors in the code.