I have a custom editor wich has a static field.
Suppose you have a static field of type MyObject
:
public class myEditor : Editor {
...
private static MyObject myObj;
...
}
I'd like to initialize the field myObj
directly on the same line of the declaration, but in this way I get a TypeInitializationException
.
I could initialize the field myObj
in the method OnEnable
, but in this way I have to use an if statement like the following:
if ( myObj == null )
myObj = new MyObject();
Is there a way to initialize myObj
once for all without using if statement?
field
shouldn't be there and would cause a compilation error. \$\endgroup\$TypeInitializationException.InnerException
property? \$\endgroup\$