String to IMaterial.

Is there a way to get an IMaterial from the string returned buy Entity:GetMaterial?

[lua]local imat = Material( ent:GetMaterial() )[/lua] ?

I Didnt think that would work, ill try it now.

[editline]9th August 2016[/editline]

Nah, doing Material(entity:GetMaterial()) return nothing.

Print what GetMaterial returns.

[editline]9th August 2016[/editline]

You’ll need to strip the vmt/vtf extension.

Weird, seems doing Entity:GetMaterial() return nothing where as Entity:GetMaterials()[1] gives me a materials, not sure if thats a gmod bug or something.

What kind of entity is it?

GetMaterial() will only return a material if one such material was set by SetMaterial().

It does not include the .vtf or .vmt extensions.

If you want to get the base/standard/normal textures of a model, use GetSubMaterial() function. Look up how it works on the wiki.

Well I looked all entities on the map, and printed e:GetMaterial() and every single entitie printed an empty string.

Yeh I never set the materials but I was so sure that GetMaterial worked before on any entity, even if I never set one first as it returns the entities default material, such as models/something/seomthing for a prop.

That was never the case, simply because that is not wghat the function does and because a model can have up to 32 materials.

[editline]11th August 2016[/editline]

This is what you are looking for.