Search Unity

TextPlane rendered when inactive

Discussion in 'Scripting' started by Overnaut, Jan 6, 2018.

  1. Overnaut

    Overnaut

    Joined:
    Aug 25, 2017
    Posts:
    19
    Straight to the point:

    When I hover a button the TextPlane shows, but when I leave the button with the cursor and the text plane is set to inactive in the editor the TextPlane is still showing. When I hover another button, nothing changes.

    It should work as follows, I have a textPlane which is activated when buttons are hovered and hidden when the cursor leaves the hovered buttons. The code managing the SetActive method for the TextPlane is in one script on each single button:

    Code (CSharp):
    1.     /*Show the corresponding tooltip, play the attached sound, and filter (dim) all incompatible buttons.*/
    2.     public void OnPointerEnter (PointerEventData eventData)
    3.     {
    4.         SGameController instance = SGameController.Instance;
    5.      
    6.         if(!instance.textPlane.activeSelf){
    7.             instance.textPlane.SetActive (true);
    8.             instance.tooltipHeader.text = tooltipTexts [toolTipIndex];
    9.             instance.tooltipText.text = tooltipTexts [toolTipIndex + 1];
    10.             gameObject.GetComponent<AudioSource>().Play ();
    11.  
    12.             if (persistentIndex == SConstant.DEFAULT_INDEX && toolTipIndex <= 22) // Only object buttons broadcast if the ground was clicked
    13.                 instance.canvas.BroadcastMessage ("FilterButton", new FilterOptions (toolTipIndex));
    14.         }
    15.     }
    16.  
    17.     /*Hide the corresponding tooltip and revoke the filtering.*/
    18.     public void OnPointerExit (PointerEventData eventData)
    19.     {
    20.         SGameController instance = SGameController.Instance;
    21.  
    22.         if(instance.textPlane.activeSelf){
    23.             instance.tooltipHeader.text = null;
    24.             instance.tooltipText.text = null;
    25.             instance.textPlane.SetActive (false);
    26.             gameObject.GetComponent<AudioSource>().Stop();
    27.  
    28.             if (persistentIndex == SConstant.DEFAULT_INDEX && toolTipIndex <= 22) // Only object buttons broadcast if the ground was clicked
    29.                 SGameController.Instance.canvas.BroadcastMessage ("FilterButton", new FilterOptions ());
    30.         }
    31.     }
    The name SGameController is self explanatory, but what my be important is that this very class is a thread save singelton pattern from https://answers.unity.com/answers/20953/view.html. I don't see why this should cause any problems, but who knows.

    Additionally, a short and small explanation .mp4 video with the size of 171.3 KB to show the error: http://turbobit.net/q0jbdfxo4j2z.html. Sorry for the link but .mp4 files are not allowed to upload here in this forum.
     
    Last edited: Jan 7, 2018
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    Weird. Maybe comment out some of the lines besides SetActive and see if it does anything.
     
  3. Overnaut

    Overnaut

    Joined:
    Aug 25, 2017
    Posts:
    19
    Thanks for your reply, I remembered that I already tried this but I retried it again now with:
    Code (CSharp):
    1. /*Show the corresponding tooltip, play the attached sound, and filter (dim) all incompatible buttons.*/
    2.     public void OnPointerEnter (PointerEventData eventData)
    3.     {
    4.         SGameController instance = SGameController.Instance;
    5.      
    6.         if(!instance.textPlane.activeSelf){
    7.             instance.textPlane.SetActive (true);
    8.             // instance.tooltipHeader.text = tooltipTexts [toolTipIndex];
    9.             // instance.tooltipText.text = tooltipTexts [toolTipIndex + 1];
    10.             // gameObject.GetComponent<AudioSource>().Play ();
    11.  
    12.             // if (persistentIndex == SConstant.DEFAULT_INDEX && toolTipIndex <= 22) // Only object buttons broadcast if the ground was clicked
    13.             //     instance.canvas.BroadcastMessage ("FilterButton", new FilterOptions (toolTipIndex));
    14.         }
    15.     }
    16.  
    17.     /*Hide the corresponding tooltip and revoke the filtering.*/
    18.     public void OnPointerExit (PointerEventData eventData)
    19.     {
    20.         SGameController instance = SGameController.Instance;
    21.  
    22.         if(instance.textPlane.activeSelf){
    23.             // instance.tooltipHeader.text = null;
    24.             // instance.tooltipText.text = null;
    25.             instance.textPlane.SetActive (false);
    26.             //gameObject.GetComponent<AudioSource>().Stop();
    27.  
    28.             // if (persistentIndex == SConstant.DEFAULT_INDEX && toolTipIndex <= 22) // Only object buttons broadcast if the ground was clicked
    29.             //     SGameController.Instance.canvas.BroadcastMessage ("FilterButton", new FilterOptions ());
    30.         }
    31.     }
    As expected, the text is now different, but the problem remains the same. The first TextPlane activation shows the TextPlane, then its rendering is independent from other TextPlane.SetActive() invocations. When I hide the canvas and render the canvas again the TextPlane is hidden though. But on hover, the malfunction of rendering the TextPlane only once restarts.

    /Edit:
    I now also tried to put the TextPlane as field in the script with the two methods posted above. Then I draged and dropped the textPlane, tooltipHeader, and tooltipText objects in the editor into their inspector fields. Nothing on the already described malfunctioning behavior changes.
     
    Last edited: Jan 7, 2018
unityunity