C# Coding error

I get the error Expression denotes a type', where a variable’, value' or method group’ was expected whenever I try to do this code:

mat = EditorGUILayout.ObjectField(mat, Material, true);

People say you use the ‘new’ keyword before it, but I couldn’t get it to work.

1 Answer

1

I see HERE that they use typeof(SomeType) instead of the way you have it “Material”. If that isn’t the problem, your single line of code looks similar to the script reference so I’m betting the problem is not this line of code.

When using that code it has ANOTHER error. :( The error is: Cannot implicitly convert type UnityEngine.Object' to UnityEngine.Material'. An explicit conversion exists (are you missing a cast?) I defined the variable 'mat' as a Material at the beginning of the script.

Oh wow thats a easy fix! Thanks a bunch!

or mat = (Material)EditorGUILayout.ObjectField(mat, typeof(Material), true); using as Material, you would still have to check for nullity, prefix casting will crash if not possible. It depends what you are after.