Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by Khena_B · Jun 01, 2017 at 12:28 PM · updateexecuteineditmode

ExecuteInEditMode issue

I have a script with [ExecuteInEditMode] and Update is only called when the gameobject is moved etc, i would like to do something when the object is selected but it is not being called because of this, is there a way to have Update run all the time?

Comment
Add comment
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

1 Reply

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

Answer by FM-Productions · Jun 01, 2017 at 01:17 PM

As you can see in https://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html the update is only called when something in the scene changes, for example panning around the scene. From the article:

"OnGUI is called when the Game View recieves an Event. "

Maybe you could do something with that information and try to implement it in the OnGUI method. But is it really necessary to execute updates in regular intervals?

Use this to check your selected gameObject:

https://docs.unity3d.com/ScriptReference/Selection-activeGameObject.html

if Selection.activeGameObject is your desired gameObject in the current update, but was not your desired gameObject in the previous frame, apply your logic.

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 Khena_B · Jun 01, 2017 at 01:20 PM 0
Share

I'm already using Selection.Contains(gameObject) and OnGui isn't helping, i really want an execution in my code every time the gameobject is selected, i don't need the Update every frames but at least once when the selection happens so i'm trying to find a solution.

Right now i'm thinking about adding a menu option on right click that would execute my function.

avatar image FM-Productions · Jun 01, 2017 at 01:21 PM 0
Share

$$anonymous$$aybe you could abuse the OnDrawGizmosSelected function, but I don't know if that works.
https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnDrawGizmosSelected.html In the function, check if you are in the Editor, then apply your logic:

 if (Application.isEditor) {
    //your logic
 }
avatar image Khena_B FM-Productions · Jun 01, 2017 at 01:26 PM 0
Share

OnDrawGizmosSelected() Worked perfectly, not sure why i haven't found that workaround anywhere, thanks!

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

66 People are following this question.

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

Related Questions

ExecuteInEditMode is not working. 1 Answer

[WORKAROUND] How to time pause in update (yield) 1 Answer

I need to call something only once in Update(). (??) 1 Answer

Why does this have to be in an update method? 1 Answer

How to increase the speed of the character in OnTriggerEnter function? 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