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
0
Question by Aubrey-Falconer · Mar 29, 2011 at 05:56 PM · javascripteditor-scriptingupdatedelegatebce0051

How to assign multiple EditorApplication.update delegates in JS?

I have an object which needs to tie into the editor's update loop to keep itself up to date. I thus added this code to it's primary JS script:

#if UNITY_EDITOR
function OnEnable() {
    EditorApplication.update = Update;
}
#endif

I also need to have multiple object's of it's type in a scene, so I modified the code to this:

#if UNITY_EDITOR
function OnEnable() {
    EditorApplication.update += Update;
}
function OnDisable() {
    EditorApplication.update -= Update;
}
#endif

Unfortunately, Unity's compiler balks at the syntax:

BCE0051: Operator '+' cannot be used with a left hand side of type 'function(): void' and a right hand side of type 'function(): void'.

Isn't this a basic feature of delegates? Am I doing something wrong, or is Unity's js implementation totally screwed up? (I know we couldn't create multidimensional arrays for quite a while, is this a similar type of issue?) If so, what's the best way to work around it?

Here's some similar topics:

http://answers.unity3d.com/questions/15889/editorapplication-update-resetting

http://forum.unity3d.com/threads/9679

http://msdn.microsoft.com/en-us/library/ms173175(v=vs.80).aspx

Comment
Add comment · Show 1
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 Aubrey-Falconer · Mar 29, 2011 at 06:05 PM 0
Share

Here's an idea - would I be best off creating my own delegate manager, such as this: http://answers.unity3d.com/questions/48542/how-can-i-declare-a-static-public-delegate-in-js ? I still can't imagine how this solution could work nicely with other objects that bypassed the manager...

2 Replies

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

Answer by Mike 3 · Mar 29, 2011 at 06:39 PM

Unityscript doesn't support it

I would make a simple c# script which exposes static Add and Remove functions, which do += and -= for you

Comment
Add comment · Show 1 · 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 Aubrey-Falconer · Mar 31, 2011 at 02:09 PM 0
Share

Works good, thanks. I sure look forward to the day when each language is fully supported though...

avatar image
1

Answer by Andrew 10 · Oct 25, 2011 at 10:26 AM

Try (instead of += which does not work in JS):

 var cb:EditorApplication.CallbackFunction = Update;//function Update
 
 EditorApplication.update = System.Delegate.Combine(cb, EditorApplication.update);
Comment
Add comment · Show 1 · 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 steinbitglis · Dec 01, 2011 at 05:58 PM 0
Share

Hmm.. I'm not allowed to vote, but 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

2 People are following this question.

avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

C# and JavaScript Event system causing 1 Answer

Input.GetMouseButtonDown(0) running through my if statments too quickly 1 Answer

WebGL prevent Unresponsive script warning 1 Answer

Setting Scroll View Width GUILayout 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