0
\$\begingroup\$

I am attempting to draw gizmos for easy debug in the editor. The gizmos code uses an array that gets populated during the start function. The array only needs to be populated once and may cause issues if its modified during runtime. As such, I cant call the method to populate the array in the OnDrawGizmos() method.

I could possibly use a singleton populate the array but that would require many other things to be changed as well. I am looking for an equivalent to Start() for when it is in Editor Mode. Is there a method in editor mode that execute once or an attribute for the Start() method to execute in editor mode?

\$\endgroup\$
  • \$\begingroup\$ I completely did not understand your question. \$\endgroup\$ – Almo Dec 7 '15 at 22:10
1
\$\begingroup\$

What you are looking for is OnEnable in the Editor class.

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

Here's some sample code from the docs:

using UnityEditor;
using UnityEngine;
using System.Collections;

// Custom Editor using SerializedProperties.
// Automatic handling of multi-object editing, undo, and prefab overrides.
[CustomEditor(typeof(MyPlayer))]
[CanEditMultipleObjects]
public class MyPlayerEditor : Editor {
    SerializedProperty damageProp;
    SerializedProperty armorProp;
    SerializedProperty gunProp;

    void OnEnable () {
        // Setup the SerializedProperties.
        damageProp = serializedObject.FindProperty ("damage");
        armorProp = serializedObject.FindProperty ("armor");
        gunProp = serializedObject.FindProperty ("gun");
    }
...
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.