• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Deadcow_ · Dec 24, 2015 at 10:51 AM · inspectornullpropertydrawerattributefield

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:

alt text

2015-12-24-13-40-15-finalstation-microsoft-visual.png (18.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
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:

MustBeAssignedAttribute

MustBeAssignedAttributeChecker

This attribute tracks nullrefs, empty strings, arrays and value types with default values on game start (in editor) alt text

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

32 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Property Drawer and Children 3 Answers

Preventing users from editing specific properties in any arbitrary inspector _without_ creating custom inspectors? 0 Answers

AttributeDrawer: Draw parent property? (the one [AttributeName] is attached to) 0 Answers

Does Unity have a "Nice Name" method? 1 Answer

Can you use Editor.DrawDefaultInspector() inside a property drawer? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges