Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by ahottev · Jan 10, 2012 at 02:07 PM · booleansendmessage

SendMessage and boolean... my GO doesn't keep the value.

Hi,

So this is probably a really dumb question since it's my first project in Unity, but here goes anyways.

To clarify things, the plane is a "card" that when the user hover over it with the mouse, a selection gizmo should appear (visual feedback). Now, when the mouse is over the plane, it sends "true" via the gizmo's Switch function. So far, this works. The problem is that at Update(), the value is set back to false every time.

There is nothing else in my project besides the plane (card) and the gizmo.

I have this plane with this script:

 public GameObject gizmo;

 void OnMouseOver()
 {
     gizmo.GetComponent<GizmoBehavior>().Switch(true);
 }
 
 void OnMouseExit()
 {
     gizmo.GetComponent<GizmoBehavior>().Switch(false);
 }

and then this simple Script attached to my "gizmo":

 private bool bIsVisible;

 
 // Update is called once per frame
 void Update () {
     Debug.Log(bIsVisible);
 }
 
 public void Switch(bool state)
 {
     // true = on (visible)
     // false = off (not visible)
     bIsVisible = state;
     Debug.Log("Switch : " + bIsVisible);
 }

Now, this is the console output:

 False
 UnityEngine.Debug:Log(Object)
 
 Switch : true
 UnityEngine.Debug:Log(Object)

... Meaning the value is correctly passed to my gizmo but somehow at Update() the value is reset back to false. I don't understand why.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bicko · Jan 10, 2012 at 02:45 PM

I suspect that what's happening is that your gizmo is popping up on top of your card, thus your mouse is actually over the gizmo and not the card. Of course this means that the gizmo is then turned off because you're not over the card, and then you're over the card again.. ad infinitum.

Comment
Add comment · Show 5 · 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 ahottev · Jan 10, 2012 at 02:56 PM 0
Share

No, it's not that. The feature works: when i hover the card, my Debug shows that it send "true" as a value to my gizmo, but at Update(), my gizmo still has "false" as a value for bIsVisible.

Besides, all the code you see, is all the code i have in my project right now, there's nothing else.

avatar image Bicko · Jan 10, 2012 at 03:26 PM 0
Share

Really weird, it's working perfectly for me when I put those 2 scripts together and put them on 2 separate objects.. you're obviously using the right object for gizmo since you're not getting a NullReferenceException.

In my Debug I'm getting this:

 False
 UnityEngine.Debug:Log(Object)
 
 False
 UnityEngine.Debug:Log(Object)
 
 Switch : True
 UnityEngine.Debug:Log(Object)
 
 True
 UnityEngine.Debug:Log(Object)
 
 Switch : True
 UnityEngine.Debug:Log(Object)
 
 True
 UnityEngine.Debug:Log(Object)
avatar image ahottev · Jan 10, 2012 at 03:29 PM 0
Share

Well, i seem to have found a solution, but i have no idea why.

this works:

 //gizmo.GetComponent<GizmoBehavior>().Switch(true);

 GameObject test = GameObject.Find("SelectGizmo");

 test.GetComponent<GizmoBehavior>().Switch(true);

Any idea why?

avatar image Bicko · Jan 10, 2012 at 03:38 PM 0
Share

Not sure, it should be working! (It certainly is here). Here's the whole Script I made off your one, maybe something weird is going on?

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$yScript : $$anonymous$$onoBehaviour
 {
     public GameObject gizmo;
     
     void On$$anonymous$$ouseOver()
     {
         gizmo.GetComponent<GizmoBehavior>().Switch(true);
     }
     
     void On$$anonymous$$ouseExit()
     {
         gizmo.GetComponent<GizmoBehavior>().Switch(false);
     }
 }
avatar image ahottev · Jan 10, 2012 at 03:53 PM 0
Share

Weird. I have the exact same script. Thanks for the help, anyway! ;)

avatar image
0

Answer by ahottev · Jan 10, 2012 at 03:53 PM

Ok, i found the answer, but if anyone could explain why it works, i'd feel a little more intelligent.

Here's the solution:

 //gizmo.GetComponent<GizmoBehavior>().Switch(true);
 GameObject test = GameObject.Find("SelectGizmo");
 test.GetComponent<GizmoBehavior>().Switch(true);

Why is this working actually?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Turn based games turn manager is spazzing out 2 Answers

Door Opening 1 Answer

How can i keep making the SendMessage repeat as long as the boolean is true 1 Answer

Help with boolean updating on all instances of script 2 Answers

How to add a script to my script ? 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