• 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 /
  • Help Room /
avatar image
Question by nonlin · Sep 27, 2014 at 04:14 AM · guifunctionsonclick

Unity 4.6 Button OnClick's Functions not showing.

I've made public functions in my scripts and attached the objects to the OnClick but I can't select or see any functions from the script.

Comment
illustir
allenrobot
anisabboud
Marc-Uberstein
zedzag
King_Arthur
naXa
OliverM22
InsOp
PonchoLira
Bob-The-Zealot
Catherine-Cail
samueldaviesaltran
RAMIJ1999
krolth
And 8 more...

People who like this

23 Show 4
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 Valcaris · Sep 30, 2014 at 10:20 PM 0
Share

I'm having the same issue. If it helps, here's more information: I'm using Unity 4.6.0b17. I've tried adding a few imports (using UnityEngine.UI and using UnityEngine.Events), I've tried using all of the different function signatures mentioned in the tutorial (making sure they're all public void). I've also tried inheriting from only MonoBehavior and also inheriting from nothing. All I get are two options: No function and Monoscript -> string name. None of the functions I'm putting in show up at all. I have even tried creating a brand new project, creating one button, creating one script with a function named public void foo(){} and still nothing shows up.

Any suggestions or other help would be appreciated. BTW, I am aware of adding it manually to the script to subscribe to the button handler. This is specifically looking at a possible issue in Unity.

avatar image Kiwasi · Oct 02, 2014 at 06:37 PM 0
Share

The script with the class declaration and method would help.

Also a screen shot of the inspector with the button selected.

avatar image byoman · Jun 19, 2015 at 02:56 PM 0
Share

hi there, I've got the same problem and I've tried all your solutions and it still don't work, I've checked that my methods use int or nothing, that the return type is void, that they're all public methods, but nothing show up whn I want to assign a method to the button T.T

avatar image byoman · Jun 19, 2015 at 02:58 PM 0
Share

( does it matter if I've deleted start and update? 'cause I don't use them)

10 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by VincentZgueb · Oct 02, 2014 at 03:52 PM

Try this:

  • create an empty object in your scene

  • Attach your script to it (Drag and drop your script into that object inspector to create a scrip component)

in button

  • Drag and drop the object created above in the Object field on the OnClick event (and not the script itself from your Project tree)

That should work.

Comment
illustir
Meriem
anisabboud
anhxvii
Marc-Uberstein
nandomclaren
FireballXL5
Robby-rEINEWALD
RyanAchtenSoma
Tea_Doogun
Ark3typ3
Wolfbane54
StevoKeano
Pejovski
DonaldTheDeveloper
And 54 more...

People who like this

69 Show 6 · 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 Valcaris · Oct 02, 2014 at 09:15 PM 0
Share

Thanks VincentZgueb! It seems like there's still a bug here, but your suggestion did work for me. I'd +1 but it says I don't have enough reputation :(

avatar image VotaVader · Nov 07, 2014 at 07:25 PM 1
Share

This didn't work for me. In fact, that's exactly what I had done, but my public methods for the script don't show on the drop-down. It seems it only shows the native GameObject methods. Has anyone had the same problem?

avatar image VotaVader · Nov 07, 2014 at 10:25 PM 6
Share

Ok, I figured it out. I hadn't noticed that the methods for On Click have to return void, and only accept int, float, bool, string, and Object parameters. My method received an enum, so I had to change it.

avatar image ariefnur652 · Mar 15, 2018 at 01:42 AM 1
Share

quick side note, if your function still doesn't appear, maybe it is because it has 2 or more Parameters in it, it seems unity only support 1 parameter at a time for function in button interface.

avatar image galatanubogdan14 · Apr 29, 2018 at 07:19 AM 0
Share

Thanks! It works if I drag the canvas in the button.The canvas need to have the script attached!

Show more comments
avatar image

Answer by jsawicki · Jun 08, 2015 at 07:23 AM

I had the same issue - here is what worked for me.

I was dragging the script directly to the button, which doesn't work. I needed to drag the object which contains the script onto the button!

After i did that, the functions showed up!

Comment
BATzerk
wsgb
Zarog
Oneesama
Necro_Infernus
baroquedub
peledkfir
tekthis
ZeroDeng88
PonchoLira
breban1
damobe
duke_meister
krolth
steveh2112
And 8 more...

People who like this

23 Show 0 · 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

Answer by JackTenSeven · Jun 03, 2016 at 06:05 PM

I have your answer! You need to make sure that the function that your trying to put on the button is a public function. If that doesnt work right away just re reference you object containing the script :)

Comment
TheCatalyyst
willcthomson
tewort

People who like this

3 Show 0 · 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

Answer by zedzag · Jul 15, 2015 at 10:53 AM

see Diego's response: http://answers.unity3d.com/questions/972191/why-wont-my-function-show-up-in-the-onclick-area-o.html

Comment
Sonoshee
U_Ku_Shu

People who like this

2 Show 0 · 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

Answer by StormMuller · Aug 07, 2016 at 01:43 AM

Make sure your method is void, public and has no more then 1 parameter.

examples:

 public void Methodname()
 {
 
 }
 
 public void Methodname(string param)
 {
 
 }
 
 public void Methodname(bool param)
 {
 
 }

Also make sure your class and/or method is not static. Attach the script to a GameObject and drag the gameobject onto the onClick event in the inspector. Select the method you wish to execute on the click.

Comment
alaplandia
Tragicoma

People who like this

2 Show 0 · 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
  • 1
  • 2
  • ›

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

30 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

Related Questions

Is it possible to use a GUI Button (On Click) to force Input keyboard commands like spacebar for Jump? 2 Answers

is there a way to ignore a click when i press on a button? 1 Answer

Button OnClick function? 1 Answer

OnClick Functions Not Appearing,OnClick Not Showing Public Functions 1 Answer

Android GUI Button crash 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