Hey guys,
Searching for an answer
Did a google search and then a search on here - also have looked through the docs but as per usual Unity seem to not provide much information about some basic aspect of their API that I’m befuddled by - but am yet to find anything on the subject; maybe I’m just not searching the right things.
The Situation
So recently I’ve started looking in to building custom inspectors using the Editor classes, and for the most part have not run in to anything I couldn’t find a quick answer to, until now. I have a class with a private field that I want to have editable through the inspector but only be read only through code. The general solution for this is to just mark it as [SerializedField], which I can confirm works in every other use case I’ve implemented.
However, I’m using a completely custom inspector (not using the draw default method). Looked this up and the workflow seems to be to use the SerializedObject class as a wrapper for my instance. The issue here being that my class doesn’t inherit from UnityEngine.Object. As it stands, the class just inherits System.object (by default as no explicit base class is specified) so I thought I’d just be able to inherit from UnityEngine.Object and all would be well…
The Problem
Bringing us to the actual problem: I instantiate the class via the usual method ( new MyClass() ), but now that it’s subclassing the Unity Object class it seems to always be null. So my code is like this:
var instance = new MyClass();
Debug.Log(instance);
When it inherits from Object, that logs as null, without the inheritance, it works fine. So is there some caveat to instantiating the Object class? Do I need to subclass something else instead? Or is it one of those Unityisms?
Thanks in advance for any insight anyone can give me.