x


Compare if object is assigned specific Material

I want to find out if a certain material is assigned to an object. The problem I am encountering is that the material I want to check for equality with is assigned by an exposed variable in the inspector ( not instanced), and my other material is instanced.

In this code, materialNeeded is assigned in the inspector, and obj is the object

var materialNeeded : Material; //Assigned through inspector

function checkIfMissionCompleted( obj : Transform )
{
   if( materialNeeded == obj.renderer.material )
   {
     //Magic
   }
}

This code never returns true. This is because the objects that I send in have had their materials assigned during runtime ( which they should ), and that makes Unity clone a runtime instance for them.

So how do I find out which the prototype material was?

more ▼

asked Apr 21 '10 at 09:50 AM

ZanzibarDreams gravatar image

ZanzibarDreams
273 10 12 22

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

What you are looking for is the renderer.sharedMaterial variable, which contains the non- instanced version of the Material. Hope it helps! Peace!

more ▼

answered Apr 21 '10 at 09:52 AM

TheDude gravatar image

TheDude
64 1 1 9

Ah, exactly what I was looking for! Peace!

Apr 21 '10 at 09:55 AM ZanzibarDreams
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x813
x467
x203
x52
x15

asked: Apr 21 '10 at 09:50 AM

Seen: 1738 times

Last Updated: Apr 21 '10 at 09:50 AM