Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
2
Question by ThePunisher · Jan 20, 2012 at 08:42 PM · editorparticle emitterexecuteineditmodeedit mode

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.

Comment
Add comment · Show 2
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
avatar image Thom Denick · Jan 20, 2012 at 09:38 PM 0
Share

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.

avatar image ThePunisher · Jan 20, 2012 at 11:45 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Bunny83 · Jan 21, 2012 at 01:55 AM

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.

Comment
Add comment · Show 3 · 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
avatar image ThePunisher · Jan 21, 2012 at 02:35 AM 0
Share

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.

avatar image ThePunisher · Jan 21, 2012 at 04:02 AM 0
Share

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

avatar image kurtdog · Apr 14, 2016 at 04:07 PM 0
Share

Hey Punisher,

Can you post your solution? I'm trying to get a particle system to emit from the editor as well. I'm using the EditorApplication.update delegate as Bunny described. Here's my code:

        void OnEnable()
         {
             
             EditorApplication.update += EditorUpdate;
         }
         void OnDisable()
         {
             EditorApplication.update -= EditorUpdate;
         }
 
       void EditorUpdate()
       {
         if(simulate)
         {
           Debug.Log(".");
           //this doesn't work
           myParticleSystem.Emit(pos, Vector3.zero, particleSize, particleLifetime, color)
 
          //but this does!
          myParticleSystem.Emit(1)
         }
 
 }
 

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.

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

What Does "ExecuteInEditMode" Actually Do? 1 Answer

Manually triggering a script from the editor (utility, macro etc.) 1 Answer

Input.mousePosition not working in edit mode 1 Answer

Execute in EditMode every time a script's parameter is changed 0 Answers

Deactive ExceuteInEditMode for Methods of Inherited Classes 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges