Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to check if a property is assigned through the inspector for a gameobject in EditorWindow code.

Discussion in 'Editor & General Support' started by harryblack, Nov 25, 2021.

  1. harryblack

    harryblack

    Joined:
    Dec 26, 2016
    Posts:
    19
    I have a component attached to a gameobject with following fields.

    upload_2021-11-25_18-6-11.png

    Now I have an EditorWindow code to check whether, say, the rigidbody field has been assigned some RigidBody in the inspector for that particular gameObject.
    How do I do that?
     
  2. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,052
  3. harryblack

    harryblack

    Joined:
    Dec 26, 2016
    Posts:
    19
    I think I couldn't describe my problem well enough.
    What I want to know inside of my EditorWindow code is whether a particular field of a component (on a particular gameobject) has been assigned a value in the inspector or not?

    I want to create a setup verification script that can tell me that my gameobject is setup correctly before going into Play Mode.

    Just like say inside a Monobehaviour I can put the null check to verify whether a value was assigned or not but that will happen when we are in Play Mode.
    I want similar check in Edit Mode inside my EditorWindow class.

    Hope I was able to describe better this time.

    @dorusoftware
    Thanks for your response anyways.
     
  4. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,052
    you need to use "editor" scripting basically.

    https://docs.unity3d.com/ScriptReference/Editor.html

    or here

    https://docs.unity3d.com/Manual/editor-CustomEditors.html

    down the page there is:

    Code (CSharp):
    1. When you enter Play mode, the GameObject that you attached the script to now orientates itself towards the coordinates you set to the “Look At Point” property. When writing Editor scripts
    2. , it’s often useful to make certain scripts execute during Edit mode, while your application is not running. To do this, add the ExecuteInEditMode attribute to the class, like this:
    which look like is what you need