- Home /
Casting Object to Material
Hi guys, I'm having error while casting object to material.
InvalidCastException: Cannot cast from source type to destination type.
What I'm trying to do is something like this:
mTarget.mMaterial = (Material)EditorGUILayout.ObjectField("Material", mTarget.mMaterial, typeof(Object));
I'm setting an object field in the Editor and it would be taking all the materials, so at the end I need to cast it back to material type.
Is there any solution for this?
Comment
I don't get that error. Are you sure mTarget.m$$anonymous$$aterial is a $$anonymous$$aterial?
Answer by birdkingz · Jun 06, 2011 at 03:32 AM
Hmm, it's weird that suddenly the error is gone :( What the hell.....