- Home /
How to get material name from instance
Below are some code wich instanciates a model. Now I want the models material name to be printed in the Debug.Log. Ive tried a bit with instance.GetComponent but cant get it to work. Anyone know the solution?
var instance : GameObject = Instantiate(Resources.Load(targetModel)) as GameObject;
Debug.Log(???);
Answer by Anxo · Jun 11, 2011 at 01:29 PM
I think materials inherent the name function.
Try
instance.material.name
guessing.
Answer by Jon-Martin · Jul 06, 2011 at 02:58 PM
material.name.Replace("(Instance)","");
make sure "(Instance)" is typed correctly otherwise it will not replace it
Answer by jukke · Jun 11, 2011 at 03:29 PM
Thanks!
One thing thou, Currently it prints out: "red (instance)" in the debug log. Is it possible to somehow only get the name: "red". Or how do I remove "(instance)" from the string?
I cast the material as a string. var varName : String;
Then I took the varName and did name only. var varNameOnly = varName.Substring(0,1);
If you need more explanation, let me know.
Your answer
Follow this Question
Related Questions
How to access scripts other than by name. 1 Answer
Is it possible to change FBX properties without using 3D modeling program? 0 Answers
Pragma strict : GetComponent without knowing the name of the component 3 Answers
I'm trying to change a material, texture or color and it doesnt work 0 Answers
How to make an if statement asking for the material name of an GameObject (C#) 1 Answer