- Home /
Component OnAwake or OnEnable with PropertyAttribute
I'm trying to create helper attribute, that'll check specific field is set in inspector (or maybe there is some solution already?) For instance, default check for "Not null":
[AssertField]
[SerializeField]
private GameObject _prefabReference;
And I need to detect "Awake()" of this component from PropertyAttribute or PropertyDrawer and do something like this:
Awake() {
Assert.IsNotNull(_referencedField,
"Field of type " + typeof(_referencedField).Name + " is null");
}
For now I'm use assertions in Awake, but sometimes it's hard to track all fields I need:
Comment
Best Answer
Answer by Deadcow_ · Sep 14, 2018 at 10:35 AM
Haha somehow google lead me to my own question over the years so I'll decided to update it with solution I made after all:
MustBeAssignedAttributeChecker
This attribute tracks nullrefs, empty strings, arrays and value types with default values on game start (in editor)