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?

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