Search Unity

changes in .onClick events in 5.2.1?[SOLVED]

Discussion in 'UGUI & TextMesh Pro' started by Eidern, Sep 29, 2015.

  1. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    98
    Hello,
    I was learning with the UI unity tutorial
    http://unity3d.com/learn/tutorials/...-training-archive/modal-window?playlist=17111

    and it seems as I was following it, that the method onClick doesn't exists anymore?

    I shortened it (full version on the tuto page : modalPanel script) here :

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.Events;
    4. using System.Collections;
    5.  
    6. public class ModalPanel : MonoBehaviour {
    7.  
    8. public Button yesButton;
    9. public void Test () {
    10. //PROBLEM HERE : the .onClick event is in red in the editor like if the method doesn't exist
    11. yesButton.onClick.RemoveAllListeners();
    12. }
    just this simple line will throw this error :
    error CS1061: Type `Button' does not contain a definition for `onClick' and no extension method `onClick' of type `Button' could be found (are you missing a using directive or an assembly reference?)
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    That should still be correct. I'm not sure what could be going wrong.
     
  3. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    98
    So could it be a bug?
    Does anyone can test this same script on a scene?
    Just a canvas with a panel and an ui button on it.
    and tell if the onclick even exists?
     
  4. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    i just copied the script to a 5.2.1p1 version and everything compiles fine.
     
  5. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    98
    ???
    So I don't understand at all, Here's a copy of my screen :


    We could see with the editor, that the event doesn't exists for the yesButton.
    Is there something OBVIOUS that I miss?
     
  6. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    557
    I know this is a long shot, but do you by any chance happen to have a custom class named Button that could cause a conflict? Just thinking out loud here.
     
    Eidern likes this.
  7. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    98
    No class named that way, but thanks for trying ;)
     
  8. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    98
    I'm currently working on a Mac with Yosemite, just in case ..
     
  9. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    what do you mean by this?
     
  10. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    98
    in the default unity script editor for mac "Mono-develop", it got a feature(i don't know how it's called there, i'm french) that suggest the methods existing for the name that you type, and if you try to wrote a method that doesn't exists for this object, the rest of the line is wrote in red, like in the screenshot above.
    So if it's in red, it'll got a compile error.

    In my screenshot the "onClick.RemoveAllListener" is in red because the onClick event doesn't exist for my yesButton Object (and when I try to execute the code anyway, i got an error)
     
  11. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Ah ok you were talking about you're development editor not the Unity editor :) i'm following now.

    So as i'm running low on ideas it almost seem like the UI dll is missing. Are you able to create UI elements in the editor (a Button for example)? if not i'd suggest redownloading 5.2.1 and seeing if that fixes it. If you can create the elements then im at a even bigger loss for whats going wrong.
     
  12. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    98
    Yes, i can create buttons and panels and so on...
    Could it be a nasty bug ?
     
  13. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    yea it sounds like a compiler bug... Like it being underlined in red could just mean the IDE isnt loading the dll. but it failing to compile as well in unity is very odd. I know its a big ask but have you redownloaded & installed Unity to see if that fixes the issue?
     
  14. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    98
    Ok I will. As soon as i get the time to re download everything I'll post the result here
     
  15. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    98
    I just redowload unity and install it : same problem :(
     
  16. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Do you get ANY other errors in the console?
     
  17. DWilliams

    DWilliams

    Joined:
    Jan 12, 2015
    Posts:
    63
    If you highlight the Button class name in the line "public Button yesButton;" and go to definition does it in fact take you to the UnityEngine.UI.Button definition like it should? I'm thinking the same as Senshi on this one, you must have a class named Button that is being used instead of the UI.Button.

    You could remove the "using UnityEngine.UI;" and see if the compiler now complains about the Button class not existing. Or you could explicitly define public UnityEngine.UI.Button yesButton;
     
    Eidern likes this.
  18. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    98
    No, the only error in the console is this one :
    Assets/Scripts/ModalPanel.cs(17,27): error CS1061: Type `Button' does not contain a definition for `onClick' and no extension method `onClick' of type `Button' could be found (are you missing a using directive or an assembly reference
     
  19. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    98
    HOLY **** !
    When I does that it redirects me to a Button.cs script that was made by another person in another temp script directory !! Now everything's explained !
    Sorry Senshi, I really didn't knew about this class, that was made for a particle effect on the store, that was stored on my particle directory. You guessed all right long ago.

    thanks again everyone, I'm ashamed that i didn't knew about this script, that i should have seen earlier :oops::oops::oops:
    But thanks again to everyone. I was quite worried.
     
    Senshi likes this.
  20. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    557
    Muahaha, I win! \0/ Glad you got it all sorted out! Happy Unitying and have fun learning more about the new UI! =)
     
    Eidern likes this.