Unity3d 4.6 GUI - button on click script disappears from prefab

I am using the new Unity3d 4.6 GUI beta. I created a canvas and attached a button to the canvas. I have hooked up the script to an empty game object using the method that the button will use. When I press the button everything works fine. However, if I turn the same canvas into a prefab when I create the prefab, the "On Click" part of the button becomes empty and the button no longer functions. I also tried to make only a prefab button instead of a canvas with a button as its child and it was the same. I really hope someone knows how to make a prefab button where the button still works.

+3


source to share


1 answer


You can get around this like I did - I ended up adding the listener button manually in the code (see below). Just make sure to do this when instantiating the prefab. The "UI way" to do this that you tried seems broken even in the latest Unity client.

    var buttonTransform = this.transform.FindChild("Button");
    _buttonScript = buttonTransform.GetComponent<Button>();
    _buttonScript.onClick.AddListener(() => Flip());

      



There is more information on this issue on the Unity website, http://answers.unity3d.com/questions/794720/on-click-paramaters-disappear-from-button-prefab.html , but I could not find the related issue reported on their team.

+2


source







All Articles