Search Unity

'IVirtualButtonEventHandler' Could not be found

Discussion in 'Vuforia' started by zara2355, Jun 17, 2020.

  1. zara2355

    zara2355

    Joined:
    Nov 17, 2019
    Posts:
    8
    Hello-

    Im very new to Unity/Vuforia and not exactly a wiz with coding, so i apologize in advance if this is a dumb question.

    I am trying to make a virtual button and following along with this tutorial:


    I am using Unity version 2019.4.0f1 and Vuforia Package 9-2-7

    The specific error i am getting is
    Assets\vb_anim.cs(6,39): error CS0246: The type or namespace name 'IVirtualButtonEventHandler' could not be found (are you missing a using directive or an assembly reference?)

    When i remove "'IVirtualButtonEventHandler" from the script, i then get an error that says:
    Assets\vb_anim.cs(16,57): error CS1061: 'VirtualButtonBehaviour' does not contain a definition for 'RegisterEventHandler' and no accessible extension method 'RegisterEventHandler' accepting a first argument of type 'VirtualButtonBehaviour' could be found (are you missing a using directive or an assembly reference?)

    If i then comment out that specific line, i do not get errors in the console, however, the virtual button does not work.

    I have no idea how to fix this

    Thanks a million in advance. Script below

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Events;
    4. using Vuforia;
    5.  
    6. public class vb_anim : MonoBehaviour, IVirtualButtonEventHandler
    7. {
    8.  
    9.     public GameObject vbBtnObj;
    10.     public Animator cubeAni;
    11.  
    12.     // Use this for initialization
    13.     void Start()
    14.     {
    15.         vbBtnObj = GameObject.Find("LacieBtn");
    16.         vbBtnObj.GetComponent<VirtualButtonBehaviour>().RegisterEventHandler(this);
    17.         cubeAni.GetComponent<Animator>();
    18.     }
    19.  
    20.     public void OnButtonPressed(VirtualButtonBehaviour vb)
    21.     {
    22.         cubeAni.Play("cube_animation");
    23.         Debug.Log("Button pressed");
    24.     }
    25.  
    26.     public void OnButtonReleased(VirtualButtonBehaviour vb)
    27.     {
    28.         cubeAni.Play("none");
    29.         Debug.Log("Button released");
    30.     }
    31. }
     
    MaritzaRodea likes this.
  2. Omar_Flayyih

    Omar_Flayyih

    Joined:
    Jun 23, 2020
    Posts:
    3
    Dear zara2355,

    In the latest update, Vuforia made some changes to the Virtual Button.

    They stopped "IVirtualButtonEventHandler" and they change the ".RegisterEventHandler(this); " you need to register the vb on button pressed also on button released

    So after these changes, the code will be like.


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Events;
    3. using Vuforia;
    4.  
    5. public class vb_anim : MonoBehaviour
    6. {
    7.  
    8.     public GameObject vbBtnObj;
    9.     public Animator cubeAni;
    10.  
    11.     // Use this for initialization
    12.     void Start()
    13.     {
    14.         vbBtnObj = GameObject.Find("LacieBtn");
    15.         vbBtnObj.GetComponent<VirtualButtonBehaviour>().RegisterOnButtonPressed(OnButtonPressed);
    16.         vbBtnObj.GetComponent<VirtualButtonBehaviour>().RegisterOnButtonReleased(OnButtonReleased);
    17.  
    18.         cubeAni.GetComponent<Animator>();
    19.     }
    20.  
    21.     public void OnButtonPressed(VirtualButtonBehaviour vb)
    22.     {
    23.         cubeAni.Play("cube_animation");
    24.         Debug.Log("Button pressed");
    25.     }
    26.  
    27.     public void OnButtonReleased(VirtualButtonBehaviour vb)
    28.     {
    29.         cubeAni.Play("none");
    30.         Debug.Log("Button released");
    31.     }
    32. }



    Cheers
    Omar Flayyih
     
    Last edited: Jun 23, 2020
  3. zara2355

    zara2355

    Joined:
    Nov 17, 2019
    Posts:
    8
    Omar, THANK YOU!!!! I am very new to this, and this was a huge help!!!

    If i may ask another question, is there a good book or other resource to help me learn C# specifically for Unity/Vuforia? I have really enjoyed learning, but i realize i have a TON more to learn. Many thanks!!!!
     
  4. Omar_Flayyih

    Omar_Flayyih

    Joined:
    Jun 23, 2020
    Posts:
    3
    Since you are new, you must start with some small projects on Vuforia and then add some complications to them, and you must understand the code and the commands before everything.

    I advise you on YouTube channels, there are a lot of projects that you can practice with, and over time, you will accumulate your experience in this field, and I think the example you published is a good start for you.

    Cheers ;)
     
  5. pforderique

    pforderique

    Joined:
    Jun 6, 2020
    Posts:
    1
    I had the exact same problem and had been searching the internet for almost half an hour. Thank you Omar!
     
  6. zara2355

    zara2355

    Joined:
    Nov 17, 2019
    Posts:
    8
    One more question, if I may?

    How does one find the new code (i.e. 'vbBtnObj.GetComponent<VirtualButtonBehaviour>().RegisterOnButtonPressed(OnButtonPressed); ')

    Is there documentation that says, "Hey, we stopped using this thing, and we changed it to this other thing"?
     
  7. Sika_MC

    Sika_MC

    Vuforia

    Joined:
    Jul 17, 2019
    Posts:
    96
    Hi @zara2355

    With 8.6.7 we changed some things see below: https://library.vuforia.com/articles/Release_Notes/Vuforia-SDK-Release-Notes

    Refactored the way how Unity application code can register for Vuforia Engine events. Instead of implementing event handling interfaces, application scripts can now register for individual callbacks. See the VuforiaSamples for more details.

    As mentioned above, our recommendation is to check our Samples, in this case, our Core Sample to see how we implemented the VirtualButton scene.

    Thank you.
    Vuforia Engine Support
     
  8. sohaib51

    sohaib51

    Joined:
    Feb 10, 2020
    Posts:
    1
    Really great help