Search Issue Tracker

Fixed in 4.6.2



Found in


Issue ID




[Button] Null references when passing gameObjects as parameters to functions called by the OnClick events



Steps to reproduce this issue:

1. Open the attached project
2. Open 'Scene'
3. Play the scene
4. Press on the button
5. Notice 'NullReference' exception
6. Select 'Acivate Menu A' button and try to assign 'Menu A' gameObject to the OnClick parameter
7. Notice it does not recognize it properly

Regression since 4.6.1p2, worked in p1
Captured here:

Comments (10)

  1. 20f20845e7bf4d6383eb4e66a861e48f?d=mm


    Feb 25, 2015 11:57

    Not solved in version 4.6.3.f1to

  2. A6080b3541faf6ec902c9a5a9a9a0211?d=mm


    Feb 16, 2015 17:47

    Ops, dind't understand the comments when I first read. Just need to patch:

  3. A6080b3541faf6ec902c9a5a9a9a0211?d=mm


    Feb 16, 2015 17:45

    Got this problem after Updating to 4.6.2.f1.

    Items dragged to a UnityEvent treat everything as GameObjects insted of getting the expected Component that the Method requires.

    A way to bypass this problem while not resolved is to create/copy the Component (e.g. Button) on the target object, then drag its target Component to the UnityEvent field (e.g. OnClick) and then copy back this Component (Button) to the original object.

  4. C7f4ead8fd001faa89be770fd81c4528?d=mm


    Feb 06, 2015 07:53

    Finally fixed :) As ODYSSEY96 said it's fixed in 4.6.2p1 :)

  5. 1cad5afef07d9fa10af6bc6906511093?d=mm


    Feb 05, 2015 23:14

    Oh just seen this is apparently fixed in 4.6.2p1 which im downloading now so if any of you guys come back here you should go to the patch download section :)

  6. 1cad5afef07d9fa10af6bc6906511093?d=mm


    Feb 05, 2015 22:54

    Right this works - although I cant believe its possible to maintain this. If you add the required component to the button itself, this will allow you to drag the component to the onclick parameter and then it will display the Name of Object (Component) as the parameter like before. When the method is called, the parameter is not null.

    This really seems to me before the editor would do a getcomponent on the dragged in object to get the component instance, now it is not doing that. If you drag the actual component in, that works fine. but i dont think you can drag the component of any other object than the current selected object as if you have multiple inspector windows, they both change when the selected object in the heirachy is changed.

  7. 1cad5afef07d9fa10af6bc6906511093?d=mm


    Feb 05, 2015 22:34

    Same issue, just updated from 4.6.1 p1 to experience this. Now here's the thing - references set before the update work fine.

    Before, references would have the component after i.e. If you specified 'MenuController' as a argument of a behaviour method, point to to this method in the onclick event and then drag an object containing a MenuController component, it would say Name Of Object (MenuController). And it still does for existing references I made in the 4.6.1 version!

    Now they just display the name of the object and end up as null variables. Could it be that the editor is not performing a getcompoent call on the object you're passing??

  8. 150d6ca076dcebce55a561882c83615f?d=mm


    Feb 05, 2015 19:26

    Same here. Not fixed in unity 4.6.2f1.
    We cannot vote on this one, should we create a new issue ?

    While waiting for the fix a workaround could be to change the type of the parameter to a gameobject (instead of the component type), and get desired component inside the method.

  9. E31526a4ba5b22d813ceb4df484245f2?d=mm


    Jan 31, 2015 11:00

    Can confirm this issue is not solved in 4.6.2f1.

    I have a function linked to a button's OnClick event in much the same way as the example project. The function has a single parameter of type Slider (though the problem is the same for all types not GameObject). The dropdown menu to select the button's linked function lists the expected parameter type as Slider, but the object selection field in which the passed reference is assigned only accepts GameObjects. Type conversion fails and the method creates a null reference error.

    Since the idea (as I understand it) is that OnClick methods should be able to have 0 or 1 parameters of a number of primitive types or any UnityObject type, this does not strike me as expected behavior. Surely, it would be quite cumbersome to only be able to pass a game object so that the receiving method still has to do a GetComponent, a null check, etc.

    I noticed this problem while following this tutorial (around the 23:48 mark):

    This tutorial was made on a 4.6 beta version, but notice how the object selection field in which he enters the slider does in fact expect an object of type Slider and does display the icon of the Slider component after it is entered. Was this functionality deliberately altered since the beta version?

  10. 5dd4c14db2b77a043c88966e79064651?d=mm


    Jan 29, 2015 19:41

    Not solved in 4.6.2.f1 as stated :(

    Items dragged into OnClick parameter is still treated as GameObject, and not the type of the receiving method.

    How do we/I change Status: Fixed to not Fixed?

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.