My UI object onclick event does not work if created from code, but works outside of it
I have a custom UI object - button that is created from code when user clicks on an object within a scene (2d game). The button is created as a child of UI_Panel object. Proper box collider 2d is set up (however it is set up in an update function as there is no way to get the button, which is a layout object, dimensions before). But the OnMouseUpAsButton() event is not called when I try to press it. Strangely enough however, If I create a new button, from the inspector directly inside canvas (not as a child of UI_Panel) all buttons in the scene start working! Even those that are children of UI_Panel. What's more , this new manually created button has to have a collider that is at least slightly inside the scene or else it doesn't work. What gives?
Your answer
Follow this Question
Related Questions
Why OnMouseUpAsButton just work for one objetc on my project 0 Answers
Collision is not working with some Collider2d 1 Answer
problem with collider detection 0 Answers
Absolutely no collision detection in build but editor is fine 1 Answer
How do you make one game object follow the shape of another game object? 0 Answers