Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

UI Button can't be clicked

Discussion in 'Project Tiny' started by AlexisSphero, Feb 25, 2021.

  1. AlexisSphero

    AlexisSphero

    Joined:
    Oct 29, 2020
    Posts:
    12
    I have been unable to get a Button with the new Tiny UI to work, at least in my project that I'm working in. Buttons work fine in the TinyRacing sample, and I went at added a Button to the Tiny3D sample along with this code and it work fine:

    Code (CSharp):
    1.                 var BackButtonEntity = World.GetExistingSystem<ProcessUIEvents().GetEntityByUIName("Button");
    2.                 var eClicked = Entity.Null;
    3.                 bool buttonTapped = false;
    4.                 Entities.ForEach((Entity e, in UIState state) =>
    5.                 {
    6.                     if (state.IsClicked)
    7.                     {
    8.                         eClicked = e;
    9.                     }
    10.                 }).Run();
    11.                 if (eClicked != null)
    12.                 {
    13.                     if (BackButtonEntity == eClicked)
    14.                     {
    15.                         buttonTapped = true;
    16.                     }
    17.                 }
    Copied the same code over to my project and the button never responds.

    I've made sure that I have the Unity.Tiny.UI as well as the Unity.Tiny.Text assembly definitions installed. I've made sure my Canvas is set to Screen Space Overlay. I've checked, through debugging and logs and my Button Entity does exist, and it is found in the ForEach loop, but it's state never gets set to IsClicked. I've tried deleting and re-adding the Canvas, the Event System and the Button but it never seems to register a click.

    I am creating Wasm builds, but AsmJS doesn't work either. It feels like there is something blocking the ray caster, but I can't find what it could be. I've also double checked that the button is set to be interactable.

    Any other ideas on what I could try?
     

    Attached Files:

  2. AlexisSphero

    AlexisSphero

    Joined:
    Oct 29, 2020
    Posts:
    12
    Okay, after a long painful amount of removing and re-adding things from the scene as well as changing there properties one by one to find the issue I have solved this.

    My main camera is set with a rotation a Y rotation of 90 and that was the issue. Setting the camera back to a Y rotation of 0 fixes the issue with the button. Unfortunately I now need to adjust all my movement code by 90 so that my main object will continue to move away from the camera in the direction I want.

    This seems like a bug, because I would assume since the UI can only be screen space Overlay, the direction of my camera should be able to rotate without inhibiting the UI.
     
  3. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319
    The main camera rotation shouldn't affect UI because we create a separate camera for UI
    Make sure that the system to detect the UI changes is being updated every frame as long as you are expecting the user to click on the buttons
     
  4. AlexisSphero

    AlexisSphero

    Joined:
    Oct 29, 2020
    Posts:
    12
    I am checking every frame on Update to see if the button is being clicked. I tried a lot variations and as soon as I change the Y rotation of the camera I stop being able to click the button. As soon as it's back to 0 the button works just fine. If it helps I am only doing wasm builds.