How to use SetMaterial()?

I am trying to use this function:

# 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

How is possible to declare a material? This does not work:

@editable
MaterialRed : material = material{}

Still trying to find a solution to this. I need to clarify how to declare a material

Material : material = DefaultMaterial

Hey! So what you need to do is expose the asset for the material, you unfortunately can’t just make it an editable field. Fortunately, exposing the material is pretty straightforward? Here’s the documentation that made things click for me: Exposing Assets

The TLDR is that you need to call the file path of the material directly to access it in scripts. Below is what a proper call looks like, from a project I’ve been working on:

CreativeProp.SetMaterial(Materials.InvisibleMat)

“Materials” is a folder in my Content Folder, and “InvisibleMat” is the filename of the material I’m setting. As long as the code can detect the material is there, that’s all you need to do! Hopefully this helps!

1 Like

Hey man, thank you so much. This works perfectly as I intended. Nobody was helping me until you appeared

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.