Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Er_Mol · May 08, 2019 at 04:19 PM · uibuttoncanvas

Button doesnt work after reactivating Canvas.

Hello,

I'm creating a Tower Defense game where the player acts as a tower. The problem that I have is when a canvas is activated after some enemies getting to the end of the maze, which shows a "GAME OVER" text and a button that takes the player back to the main menu scene. But even though I have the scene loading script attached to the button and have EventSystem in place, the button doesn't seem to respond to the mouse press. Also at the same time, the cursor disappears and I need to click Esc every time after pressing the button to see the cursor again. I've tried to see if there is something inherently wrong with the button/canvas by creating a temporary scene and pasting it, but everything worked perfectly there.

Thanks in advance for any advice.

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tormentoarmagedoom · May 08, 2019 at 04:30 PM 0
Share

Is posible you have something in front of the button? another canvas or something?

One good thing to do, is use Raycast in a script and then Debug.log the hit.gameobject.name to know what object are you cliking... maybe will show you what is happening!

Good luck !

avatar image Er_Mol tormentoarmagedoom · May 08, 2019 at 04:43 PM 0
Share

Thanks for the response. Will try, but honetly I don't know even how or why o what might be the cause.

avatar image akaBase Er_Mol · May 08, 2019 at 09:52 PM 0
Share

It does sound like the "Game Over" text is left over the button making it un-clickable.

Show more comments

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sdowmaster · May 08, 2019 at 07:47 PM

did you add the scene to the build settings?

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Er_Mol · May 08, 2019 at 08:46 PM 0
Share

Yes, I've added them. The problem is that after transitioning from the first-person camera to another camera( I use the second one for a player to be able to set position to which he can teleport) and then reactivate it along with the canvas where the game over is shown, the button doesn't even react to the mouse, and the mouse itself is not showing until I use Esc key, even though it's displayed for the first time.

avatar image sdowmaster Er_Mol · May 08, 2019 at 09:50 PM 0
Share

use a debug code to see if it is pressed and while you start the game and this happens go check the button you are pressing, if it has the script loaded or it is "missing" as happens to me due to some mistakes i made. But you say you made another scene and it worked fine so i don't understand :) i am a little more than a beginner so i don't make sense xD

avatar image Er_Mol sdowmaster · May 08, 2019 at 09:59 PM 0
Share

I'm also extremely confused. I started trying to deactivate objects bit by bit and see which may interfere, but the only time the canvas works are when I rewrite code a little bit so that the camera along with the canvas I reactivated right after deactivating. Which obviously got me nowhere.

Show more comments
avatar image
0

Answer by darkStar27 · May 09, 2019 at 05:19 AM

Here attach this script to a GameObject in your hierarchy and click on the button.

It debugs the first thing that it hits on. The problem may have occured cause of something that is lying above your button.

 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 
 public class UIObjectDetector : MonoBehaviour
 {
     public static UIObjectDetector instance;
     public EventSystem es;
     public PointerEventData ped;
     public List<RaycastResult> rr;
     public bool debug;
     
     void Awake ()
     {
         instance = this;
     }
     void Start ()
     {
         ped = new PointerEventData (null);
         rr = new List<RaycastResult> ();
     }
     public void Update ()
     {
         if (Input.GetMouseButtonDown (0) && debug) {
             IsOverUIObject ();
         }
     }
 
     public bool IsOverUIObject ()
     {
         ped.position = Input.mousePosition;
         rr.Clear ();
 
         es.RaycastAll (ped, rr);
         if (rr.Count != 0) {
             Debug.Log("Object Clicked on " + rr[0].gameObject.name + " Parent is " + rr[0].gameObject.transform.parent.name);
             if (rr [0].gameObject.layer == LayerMask.NameToLayer ("UI")) {
                 return true;
             } else {
                 return false;
             }
         }
         return false;
     }
 }

If that's not the problem, check if your button has Image attached to it and that its RaycastTarget property is checked.


Hope this Helps!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Er_Mol · May 09, 2019 at 08:17 PM 0
Share

Thanks for the reply. Still nothing, but when I started looking at the event system I noticed that when I drag the mouse over the button, the pointerEnter property shows nothing, and when I to main menu scene and do the same, every button is shown in this property.

avatar image
0

Answer by Elizabeth87 · May 09, 2019 at 11:47 AM

The problem is that after transitioning from the first-person camera to another camera( I use the second one for a player to be able to set position to which he can teleport) and then reactivate it along with the canvas where the game over is shown, the button doesn't even react to the mouse, and the mouse itself is not showing until I use Esc key, even though it's displayed for the first time. kodi

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image henrytom36 · Jul 25, 2019 at 09:48 PM 0
Share

Thank you for the share you experience with us. hulu

avatar image
0

Answer by Er_Mol · May 09, 2019 at 08:23 PM

Okay, it started detecting the button when I pressed the Esc key when the camera on my player was still active(along with the entire player). When I did that, the mouse persisted to the next camera and the event system started recognizing stuff I was hovering over. Still, there is a problem of making the cursor active before the transition.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

195 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Menu not getting Keyboard Input 0 Answers

UI button does not press if colliding with other UI object 1 Answer

How do i get the UI button position? 2 Answers

How to keep UI button from triggering game objects behind it? 0 Answers

Use Canvas Buttons as Input Axis 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges