# Programmatically extract textures from an arbitrary material

How do you programmatically extract the textures and other properties of an arbitrary Unity material?

Ideally runtime - I'm trying to upload the data to the server for remote access.

• Have you tried the methods Material.GetTexture("TexturePropertyName")? – Benjamin Danger Johnson Oct 22 '20 at 3:41
• Can you loop through the property names for an arbitrary material whose property names you might not know in advance? So for something like .GetTexture(_property[i]) where _property[i] is the list of properties, how would you populate _property[i] – ina Oct 22 '20 at 21:36

I think what you are looking for are the methods of Shader to get information about the properties and then as mentioned in the comments, use the methods of Material to get the data assigned to those properties (if any).

Below an example test where I check if the property is a texture, and log it if it is.

public class Example : MonoBehaviour
{
public Material material;

public void Start()
{

for (int i = 0; i < shader.GetPropertyCount(); i++)
{

• I'm guessing you mean the question mark in there? This is not a typo, this '?.' is a null conditional operator It means: if lhs is null don't evaluate rhs and instead return null. Meaning if texture == null, texture?.name will return null instead of throw an error complaining texture is null. It is the same as this code: (texture == null ? null : texture.name) which would be similar to if(texture==null){return null;}else{return texture.name;}. – troien Oct 28 '20 at 13:08