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 /
  • Help Room /
avatar image
0
Question by Edmonds · Sep 04, 2016 at 02:13 PM · scripting problembug

Potential bug in unity or am I misunderstanding something?

I am trying to build buttons to use in a main menu screen, I made a script and an object structure that should work for any buttons of this design. The first button I tested it on worked fine, but when I attached the script to another button (part of a dialogue box, hence different canvas) unity told me that there was a NullPointerException. In typical fashion, it didn't tell me anything specific but it at least told me that the problem was on line 11 of the script. The only problem is that, upon entering playmode, the script still works until that point (and even the line causing the error performs its task). The original button implementation also still works, the only thing that is broken about the new one is that the functions "OnMouseOver" and "OnMouseExit" don't get called.

Also trying to open the script from the error-producing gameObject causes MonoDevelop to tell me the same NullPointerException.

Image explanation of the problem. alt text

Also, I just removed the working script component from the working gameObject and reapplied it, that caused it to break as well.

The script's contents is below:

public class Menu_Button_Hover : MonoBehaviour {

 private GameObject selected_overlay;

 void Start () {
     var parent = transform.parent.gameObject;
     selected_overlay = GameObject.Find(transform.parent.gameObject.name + "/Outline");
     selected_overlay.SetActive(false);
 }

 public void OnMouseEnter(){
     print ("ExitOver");

     print (selected_overlay);
     selected_overlay.SetActive(true);
 }

 public void OnMouseExit(){
     selected_overlay.SetActive (false);
 }

}

I'm at a loss here. Any input is greatly appreciated!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Edmonds · Sep 04, 2016 at 04:37 PM

I solved the problem, it turns out that there was a problem with the script I was using. I copied the text from the script, put it into a new script and attached that to the relevant buttons. This solved the pointer issue.

The reason the button which wasn't working didn't work was because the text gameObject had "Raycast target" turned on.

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

83 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

Related Questions

[Solved] Tycoon type game, buystorebutton stays inactive & does not subtract nextstorecost from currentbalance 0 Answers

why Crossplatform input Joystick behaving weirdly with FirstPersonController from Standard Assets? 0 Answers

Why does unity not see monobehaviour? 1 Answer

Script doesnt work properly on 1 object 0 Answers

Int not increasing in correct amounts 0 Answers


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