Before updating to Windows 10 you may need to return your Pro license. More information here

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;
 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.

more ▼

asked Jan 20, 2012 at 08:42 PM

avatar image

1.9k 15 17 30

This is a good question, and I probably don't know the answer, but is it possible Particle Emitter is doing its business in the OnDrawGizmos() method? This is how I generally get things to show up only in the Scene window. Of course, that does not explain why that code would be triggering the Update method.

Jan 20, 2012 at 09:38 PM Thom Denick

Hi Smorpheus, thanks for your response. I haven't looked at OnDrawGizmos() yet, so I'll make sure I look into that. I agree with you though, I don't think that explains why it would trigger my scripts update.

Jan 20, 2012 at 11:45 PM ThePunisher
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jan 21, 2012 at 01:55 AM

avatar image

97.2k 55 301 528

Hi Bunny83, thank you for taking the time to respond. I understand the Editor scripts (or anything that references UnityEditor for that matter) can't be part of the build. As a matter of fact, I need this logic for a custom inspector and I need the object to be selected, so that would work out perfectly. Let me give your delegate suggestion a try.

Jan 21, 2012 at 02:35 AM ThePunisher

That worked perfectly, Bunny83! Thanks a lot, you've really helped me here.

Jan 21, 2012 at 04:02 AM ThePunisher
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jan 20, 2012 at 08:42 PM

Seen: 2179 times

Last Updated: Jan 21, 2012 at 04:02 AM