How does the particle emitter update in edit mode?

Ok, now this has puzzled me for a day or two, and I can’t really figure it out. Here it goes.

Does anybody have any idea how the particle emitter is able to update in edit mode? I know about the [ExecuteInEditMode] attribute, but that only seems to be called when the unity Editor has changed (new object selected or public members in the inspector were modified). I have reason to believe that the particle emitter is either triggering a specific event or calling some specific editor method that is forcing the editor to update more frequently. Here is the reason why I think this may be happening. Copy the following code into a new c# script called Example and drag the script onto a GameObject in the scene.

using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class Example : MonoBehaviour
{
   void Update()
   {
      print("Update for " + this.name + " was called.");
   }
}

Move the object around, or click on different assets in the project hierarchy, and you will notice that the print statement appears in the console window only when you change something. I know this is desired behavior because you wouldn’t want the editor updating everything part all the time if nothing is changing, of course.

Ok, now clear the console window and add a particle emitter. Select the particle emitter if it isn’t already selected and take a look at the console window. You will notice that the print statement for our script is being continuously called. If the particle emitter was simply calling the Update method of all of the particles then it shouldn’t trigger the Update method on our script, yet it does. So then what is the particle emitter doing?

The real question is…how can I get the same update behavior as the particle emitter while in edit mode of the editor (not play mode)? I know this may be sound awkward, but thanks for any suggestions, ideas, or comments in advanced.

First i’d like to say that a particle emitter is not a script, it’s a seperate component (not even a Behaviour, see the class hierarchy). Most of the built-in components are written in native code and just have an Mono / .NET interface for scripting. So if you want to achieve something similar it will work different than a particle emitter / camera / cloth / …

If you want to implement an continous update in the editor you can use the EditorApplication.update -delegate. Keep in mind that all editor functions / classes (the whole UnityEditor namespace) is not available at runtime. So you have to use either conditional compilation to exclude this extra code from your build, or implement the functionality in a custom inspector. With a custom inspector it would only work while it’s selected in the inspector.