When implementing material changes in Verse, what should I do if the mesh has multiple material elements?

When changing materials in Verse using the SetMaterial function to modify a creative_prop’s material, is it possible to change only a specific part of the prop if it has multiple material elements, rather than just a single one?

If so, how should the code be written to achieve this?

I would appreciate your guidance. Thank you.


Even when I write PaintProp.SetMaterial(Materials.PaintPicker_Black, 1),
an error still occurs.
I want to change material slot [1] to Black, but it doesn’t work.

Hello!

Sorry for the confusion!
I asked docs team to add section about defining and using optional parameters.

Correct syntax for setting value to optional argument is:

Foo(?OptionalArg := 1)

So in your case it should be:

PaintProp.SetMaterial(Materials.PaintPicker_Black, ?Index := 1)

You may also consider storing your materials in array, so whole if/else if chain could be simplified to:

if (Material := MyMaterialsArray[Index]):
    PaintProp.SetMaterial(Material, ?Index := 1)
1 Like

looking at the documentation, it seems that you have a parameter for choosing which material slot you update

# Changes the Material of the Mesh used by this instance. Optionally can specify which Mesh element index to apply the material to, otherwise defaults to the 0 (default) Mesh element
SetMaterial<native><public>(Material:material, ?Index:int = external {})<transacts>:void

SetMaterial(MyMaterial, ?Index := 2)
1 Like