Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
6
Question by Subhojit · Aug 24, 2017 at 01:40 PM · buttononclick

How to re-arrange button onclick event in unity?

I was trying move up and down the button functions, which I applied before. Unfortunately I was unable to swipe up or down the functions. Is it possible to do so? Please help.

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 WinterboltGames · Aug 24, 2017 at 01:53 PM 0
Share

No, you can't

avatar image Hellium · Aug 24, 2017 at 01:55 PM 0
Share

Even if you could, you should not rely on the order of the callbacks. AFAI$$anonymous$$, callbacks may not be called in the order they have been provided.

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by vlab22 · Jul 06, 2021 at 01:33 PM

I guess I solve it right now.

Unity 2020.3.5f1

Apparently works with all UnityEvents because of the

 [CustomPropertyDrawer(typeof(UnityEventBase), true)] //includeChildren param
 

So it's applied to all subclasses of UnityEvent

Put this code inside an Editor folder.

 using UnityEditor;
 using UnityEditorInternal;
 using UnityEngine.Events;
 
     [CustomPropertyDrawer(typeof(UnityEventBase), true)]
     public class BaseCustomUnityEventDrawer : UnityEventDrawer
     {
         protected override void SetupReorderableList(ReorderableList list)
         {
             base.SetupReorderableList(list);
 
             list.draggable = true;
         }
     }

I really don't know why it's not a default.


Code explanation,

Using the UnityEventDrawer to hack in UnityEvent custom editor.

Before this, I had lots of headaches trying to redraw, add elements, etc to the UnityEvent inspector but I've got strange errors because of how UnityEvent draws in the inspector.

Couldn't do anything override OnGUI etc.

So while researching the drawer I found this ReorderableList field (draggable) and voilá!


https://github.com/vlab22/unityevent-reordering


alt text


unity-event-reordering.gif (325.4 kB)
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 AlejUb · Jul 06, 2021 at 05:39 PM 0
Share

Another reason why threads shouldn't be locked, blocked, expired, etc. I really got nothing to add just a big massive thank you. Just bumped into this a few hours after dealing with libraries that would try to do this by hand capturing Editor events and whatnot.

avatar image
3

Answer by daviddickball · Feb 02, 2018 at 05:56 PM

Apparently we can't do this, and there's a technical reason why not. Apparently "internally this uses a delegate where call order is not defined" - there's more info and discussion about this here: https://forum.unity.com/threads/solved-unityevent-invoke-calling-order.265292/#post-1753393

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

Answer by TheFastLane · Oct 05, 2020 at 01:42 PM

I've seen the code myself, and it does have a very specific order. ...listeners shown in the inspector are called in the order shown first, then listeners added programmatically are called in the order they were added.

See @JoshuaMcKenzie answer that indicates there is a specific order here: Button On Click execution order?

If his answer is correct there should absolutely be functionality for re-arranging the event call order in the inspector.

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

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

85 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 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

Reference For Button Which Calls OnClick 4 Answers

onClick.AddListener For Button, Spams Console 0 Answers

My onclick action listeners I attach to my buttons as I instantiate them only work once 1 Answer

OnClick() problem with Button script: "Deleting an array element will copy the complete array to all..." 1 Answer

button.onClick.AddListener(method); NOT Working 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