Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Help with Vuforia project

Discussion in 'Editor & General Support' started by Spinnernicholas, Dec 4, 2013.

  1. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Lol, this is a really bad typo:

    Change

    Code (csharp):
    1. touch.phase = TouchPhase.Began
    to

    Code (csharp):
    1. touch.phase == TouchPhase.Began
     
  2. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Change all the capital Xs and Ys to lower case.
     
  3. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    now I have these errors which I am sure relate to the Vuforia update

    Assets/Scripts/ImageTargetsScripts/ImageTargetsMenu.cs(199,106): error CS0117: `Tracker' does not contain a definition for `Type'

    Assets/Scripts/ImageTargetsScripts/ImageTargetsMenu.cs(199,87): error CS1501: No overload for method `GetTracker' takes `1' arguments

    It won't let me add those scripts till I fix those of course
     
  4. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    what did you mean by "And then assign animatedObject in the preview."
     
  5. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    lol, I mean in the inspector.
     
  6. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    I still don't understand
     
  7. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    animatedObject is a public member of the class, so you can automatically edit it in the Unity Editor Inspector.

    Select the object with the script attached. In the script component, in the inspector, you should see something like "Animated Object <circle with dot>". Click on the circle with the dot and choose the object with the animation script attached to it.
     
  8. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    wow...i feel so stupid.
     
  9. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    pressing the button still does nothing
     
  10. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    here are my steps.

    assign previewanimation to 3d model
    assign button handler to button
    assign mouse handler to camera
    assign 3d model withing the button hadler
     
  11. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    here is my previewanimation script

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [ExecuteInEditMode]
    5. public class Previewanimation : MonoBehaviour
    6. {
    7.    
    8.     string stardust_waiting;
    9.     WrapMode wrapMode;
    10.    
    11.     void Awake()
    12.     {
    13.         //disable script
    14.         enabled = false;
    15.     }
    16.    
    17.     public void PreviewAnimation(string stardust_waiting, string stardust_attack)
    18.     {
    19.         //enable script
    20.         enabled = true;
    21.         //Save Animation Settings
    22.         this.stardust_waiting = stardust_waiting;
    23.         wrapMode = this.animation.wrapMode;
    24.         //Play animation once
    25.         this.animation.wrapMode = WrapMode.Once;
    26.         this.animation.Play("stardust_attack");
    27.     }
    28.    
    29.     void Update()
    30.     {
    31.         if(!animation.isPlaying)
    32.         {
    33.             //Restore Animation Settings
    34.             animation.wrapMode = wrapMode;
    35.             animation.Play("stardust_waiting");
    36.             //disable script
    37.             enabled = false;
    38.            
    39.         }
    40.     }
    41.    
    42. }
     
  12. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    PreviewAnimation keeps turning itself off
     
  13. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    and I get this warning:
    Assets/Scripts/stardust/Previewanimation.cs(8,16): warning CS0414: The private field `Previewanimation.stardust_waiting' is assigned but its value is never used
     
  14. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    delete "string stardust_waiting;" near the top.

    PreviewAnimation is supposed to turn itself off. It's only on when it is playing an animation.
     
  15. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    When I did that i got an error:

    Assets/Scripts/stardust/Previewanimation.cs(22,22): error CS1061: Type `Previewanimation' does not contain a definition for `stardust_waiting' and no extension method `stardust_waiting' of type `Previewanimation' could be found (are you missing a using directive or an assembly reference?)
     
  16. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Oh wait, I see the problem. Here you go:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [ExecuteInEditMode]
    5.  
    6. public class Previewanimation : MonoBehaviour
    7. {
    8.  
    9.     string stardust_waiting;
    10.     WrapMode wrapMode;
    11.  
    12.     void Awake()
    13.     {
    14.         //disable script
    15.         enabled = false;
    16.     }
    17.  
    18.     public void PreviewAnimation(string stardust_waiting, string stardust_attack)
    19.     {
    20.         //enable script
    21.         enabled = true;
    22.         //Save Animation Settings
    23.         this.stardust_waiting = stardust_waiting;
    24.         wrapMode = this.animation.wrapMode;
    25.  
    26.         //Play animation once
    27.  
    28.         this.animation.wrapMode = WrapMode.Once;
    29.         this.animation.Play("stardust_attack");
    30.     }
    31.  
    32.     void Update()
    33.     {
    34.         if(!animation.isPlaying)
    35.         {
    36.             //Restore Animation Settings
    37.             animation.wrapMode = wrapMode;
    38.             animation.Play(stardust_waiting);
    39.             //disable script
    40.             enabled = false;
    41.         }
    42.     }
    43. }
     
  17. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    that didn't work either.
    i still have the GUI attack we made a while back. would that cause the problem? I've been trying to remove it but can't find it
     
  18. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    found the code. but I can't remove it because it is the trackable event handler

    Code (csharp):
    1.  
    2. //Modified By: Michanikos(spinnernicholas@gmail.com) 12/05/2013
    3.  
    4. //From DefaultTrackableEventHandler.cs
    5.  
    6.  
    7.  
    8. using UnityEngine;
    9.  
    10.  
    11.  
    12. /// <summary>
    13.  
    14. /// A custom handler that implements the ITrackableEventHandler interface.
    15.  
    16. /// </summary>
    17.  
    18. public class StardustTrackableEventHandler : MonoBehaviour,
    19.  
    20. ITrackableEventHandler
    21.    
    22. {
    23.    
    24.     public Previewanimation animatedObject;
    25.    
    26.     public Rect buttonPosition;
    27.    
    28.     public string buttonString;
    29.    
    30.    
    31.    
    32.     #region PRIVATE_MEMBER_VARIABLES
    33.    
    34.    
    35.    
    36.     private bool isTracking = false;
    37.    
    38.     private TrackableBehaviour mTrackableBehaviour;
    39.    
    40.    
    41.    
    42.     #endregion // PRIVATE_MEMBER_VARIABLES
    43.    
    44.    
    45.    
    46.    
    47.    
    48.    
    49.    
    50.     #region UNTIY_MONOBEHAVIOUR_METHODS
    51.    
    52.    
    53.    
    54.     void Start()
    55.        
    56.     {
    57.        
    58.         mTrackableBehaviour = GetComponent<TrackableBehaviour>();
    59.        
    60.         if (mTrackableBehaviour)
    61.            
    62.         {
    63.            
    64.             mTrackableBehaviour.RegisterTrackableEventHandler( this);
    65.            
    66.         }
    67.        
    68.     }
    69.    
    70.    
    71.    
    72.     #endregion // UNTIY_MONOBEHAVIOUR_METHODS
    73.    
    74.    
    75.    
    76.    
    77.    
    78.    
    79.    
    80.     #region PUBLIC_METHODS
    81.    
    82.    
    83.    
    84.     /// <summary>
    85.    
    86.     /// Implementation of the ITrackableEventHandler function called when the
    87.    
    88.     /// tracking state changes.
    89.    
    90.     /// </summary>
    91.    
    92.     public void OnTrackableStateChanged(
    93.        
    94.         TrackableBehaviour.Status previousStatus,
    95.        
    96.         TrackableBehaviour.Status newStatus)
    97.        
    98.     {
    99.        
    100.         if (newStatus == TrackableBehaviour.Status.DETECTED ||
    101.            
    102.             newStatus == TrackableBehaviour.Status.TRACKED)
    103.            
    104.         {
    105.            
    106.             isTracking = true;
    107.            
    108.             OnTrackingFound();
    109.            
    110.         }
    111.        
    112.         else
    113.            
    114.         {
    115.            
    116.             isTracking = false;
    117.            
    118.             OnTrackingLost();
    119.            
    120.         }
    121.        
    122.     }
    123.    
    124.    
    125.    
    126.     #endregion // PUBLIC_METHODS
    127.    
    128.    
    129.    
    130.    
    131.    
    132.    
    133.    
    134.     #region PRIVATE_METHODS
    135.    
    136.    
    137.    
    138.     void OnGUI()
    139.        
    140.     {
    141.        
    142.         if(isTracking)
    143.            
    144.         {
    145.            
    146.             if(GUI.Button(buttonPosition, buttonString))
    147.                
    148.             {
    149.                
    150.                 animatedObject.PreviewAnimation("stardust_waiting", "stardust_attack");
    151.                
    152.             }
    153.            
    154.         }
    155.        
    156.     }
    157.    
    158.    
    159.    
    160.     private void OnTrackingFound()
    161.        
    162.     {
    163.        
    164.         Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
    165.        
    166.         Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
    167.        
    168.        
    169.        
    170.         // Enable rendering:
    171.        
    172.         foreach (Renderer component in rendererComponents)
    173.            
    174.         {
    175.            
    176.             component.enabled = true;
    177.            
    178.         }
    179.        
    180.        
    181.        
    182.         // Enable colliders:
    183.        
    184.         foreach (Collider component in colliderComponents)
    185.            
    186.         {
    187.            
    188.             component.enabled = true;
    189.            
    190.         }
    191.        
    192.        
    193.        
    194.         Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
    195.        
    196.     }
    197.    
    198.    
    199.    
    200.    
    201.    
    202.     private void OnTrackingLost()
    203.        
    204.     {
    205.        
    206.         Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
    207.        
    208.         Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
    209.        
    210.        
    211.        
    212.         // Disable rendering:
    213.        
    214.         foreach (Renderer component in rendererComponents)
    215.            
    216.         {
    217.            
    218.             component.enabled = false;
    219.            
    220.         }
    221.        
    222.        
    223.        
    224.         // Disable colliders:
    225.        
    226.         foreach (Collider component in colliderComponents)
    227.            
    228.         {
    229.            
    230.             component.enabled = false;
    231.            
    232.         }
    233.        
    234.        
    235.        
    236.         Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
    237.        
    238.     }
    239.    
    240.    
    241.    
    242.     #endregion // PRIVATE_METHODS
    243.    
    244. }
    245.  
     
  19. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    They must have changed the DefaultTrackableEventHandler.cs. Can you post it for me again.
     
  20. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    Code (csharp):
    1.  
    2. /*==============================================================================
    3. Copyright (c) 2010-2013 Qualcomm Connected Experiences, Inc.
    4. All Rights Reserved.
    5. Confidential and Proprietary - Qualcomm Connected Experiences, Inc.
    6. ==============================================================================*/
    7.  
    8. using UnityEngine;
    9.  
    10. /// <summary>
    11. /// A custom handler that implements the ITrackableEventHandler interface.
    12. /// </summary>
    13. public class DefaultTrackableEventHandler : MonoBehaviour,
    14.                                             ITrackableEventHandler
    15. {
    16.     #region PRIVATE_MEMBER_VARIABLES
    17.  
    18.     private TrackableBehaviour mTrackableBehaviour;
    19.    
    20.     #endregion // PRIVATE_MEMBER_VARIABLES
    21.  
    22.  
    23.  
    24.     #region UNTIY_MONOBEHAVIOUR_METHODS
    25.    
    26.     void Start()
    27.     {
    28.         mTrackableBehaviour = GetComponent<TrackableBehaviour>();
    29.         if (mTrackableBehaviour)
    30.         {
    31.             mTrackableBehaviour.RegisterTrackableEventHandler(this);
    32.         }
    33.     }
    34.  
    35.     #endregion // UNTIY_MONOBEHAVIOUR_METHODS
    36.  
    37.  
    38.  
    39.     #region PUBLIC_METHODS
    40.  
    41.     /// <summary>
    42.     /// Implementation of the ITrackableEventHandler function called when the
    43.     /// tracking state changes.
    44.     /// </summary>
    45.     public void OnTrackableStateChanged(
    46.                                     TrackableBehaviour.Status previousStatus,
    47.                                     TrackableBehaviour.Status newStatus)
    48.     {
    49.         if (newStatus == TrackableBehaviour.Status.DETECTED ||
    50.             newStatus == TrackableBehaviour.Status.TRACKED ||
    51.             newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
    52.         {
    53.             OnTrackingFound();
    54.         }
    55.         else
    56.         {
    57.             OnTrackingLost();
    58.         }
    59.     }
    60.  
    61.     #endregion // PUBLIC_METHODS
    62.  
    63.  
    64.  
    65.     #region PRIVATE_METHODS
    66.  
    67.  
    68.     private void OnTrackingFound()
    69.     {
    70.         Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
    71.         Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
    72.  
    73.         // Enable rendering:
    74.         foreach (Renderer component in rendererComponents)
    75.         {
    76.             component.enabled = true;
    77.         }
    78.  
    79.         // Enable colliders:
    80.         foreach (Collider component in colliderComponents)
    81.         {
    82.             component.enabled = true;
    83.         }
    84.  
    85.         Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
    86.     }
    87.  
    88.  
    89.     private void OnTrackingLost()
    90.     {
    91.         Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
    92.         Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
    93.  
    94.         // Disable rendering:
    95.         foreach (Renderer component in rendererComponents)
    96.         {
    97.             component.enabled = false;
    98.         }
    99.  
    100.         // Disable colliders:
    101.         foreach (Collider component in colliderComponents)
    102.         {
    103.             component.enabled = false;
    104.         }
    105.  
    106.         Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
    107.     }
    108.  
    109.     #endregion // PRIVATE_METHODS
    110. }
    111.  
     
  21. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Ok, remove the custom trackable event handler I wrote from the image tracker and replace it with the DefaultTrackableEventHandler.
     
  22. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    still no luck
     
  23. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    That's just one step. What errors are there now?
     
  24. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    there isn't any. just doesn't work. would it be better to just share the project folder?
    2 things that do show up in the console that is new is

    Can't add component because class 'PremiumObjectFactoryStarterBehaviour' doesn't exist!
    UnityEngine.GameObject:AddComponent(String)
    QCARAbstractBehaviour:Awake()


    and

    Can't add component because class 'PremiumComponentFactoryStarterBehaviour' doesn't exist!
    UnityEngine.GameObject:AddComponent(String)
    QCARAbstractBehaviour:Awake()
     
  25. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    You might have to trash the entire image target and recreate it. It seem's like Vuforia made quite a few code changes.
     
  26. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    ok will do
     
  27. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    im sorry its still not working
     
  28. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Ok, lets hit the checklist:

    1. You have the a fresh default image target.
    2. You have your model.... as a child of the image target.
      • My animation script is attached to same object as Animation component.
    3. You have created a button as child of image target.
      • The button has a quad with button texture.
      • The button has a collider and my touch handling script.
    4. The Camera has my input script.
     
  29. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    check to all

    $Screenshot (1).png $Screenshot (2).png $Screenshot (3).png
     
  30. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    A can't see the script on the camera, can you scroll it down for me.
     
  31. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    And this will help, right before this line on the camera script:

    Code (csharp):
    1.  
    2. hit.collider.SendMessage("OnTouch");
    Put this:

    Code (csharp):
    1.  
    2. Debug.Log("Hit Collider on Object: " +  hit.collider.gameObject.name);
    3.  
     
  32. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    lol my bad that might of been the purpose of that screen shot isn't it?

    $Screenshot (4).png
     
  33. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    lol!

    Anyways, it's all looks good structurally. Now, let's see if we can get it to work.


    I see that, on the button, the quad came with a collider(mesh collider), so delete the box collider, we don't need it.
     
  34. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    it didn't work :(
     
  35. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Do the model and the button appear correctly when tracking?
     
  36. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
  37. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Are you testing it on a phone?
     
  38. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    Yes I am
     
  39. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Ok, one sec, I'm going to modify the camera script to display debug info on the screen.
     
  40. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    ok thank you
     
  41. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Replace the camera script code with this:

    Code (csharp):
    1.  
    2. public class MouseHandler: MonoBehavior
    3. {
    4.     public bool enableDebug;
    5.     private string debugOutput = "";
    6.  
    7.     void Update()
    8.     {
    9.         if(Input.touchCount > 0)
    10.         {
    11.             Touch touch = Input.touches[0];
    12.             if(touch.phase = TouchPhase.Began)
    13.             {
    14.                 Ray ray = camera.ScreenPointToRay(new Vector3(touch.position.X, touch.position.Y));
    15.                 RaycastHit hit;
    16.                 if(Physics.Raycast(ray, out hit, 100))
    17.                 {
    18.                     debugOutput += "Touched Collider: " + hit.collider.name + "\n";
    19.                     hit.collider.SendMessage("OnTouch");
    20.                 }
    21.             }
    22.         }
    23.     }
    24.    
    25.     void OnGUI()
    26.     {
    27.         if(enableDebug)
    28.         {
    29.             GUI.Label(new rect(0f,0f,Screen.width,Screen.height), debugOutput)
    30.         }
    31.     }
    32. }
    33.  
     
  42. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    And then, in the inspector, set Enable Debug = True.
     
  43. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    it doesnt give me the option to enable
     
  44. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    there is errors:

    Assets/MouseHandler.cs(57,17): error CS1525: Unexpected symbol `}'
    Assets/MouseHandler.cs(61,1): error CS8025: Parsing error
     
  45. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    I fixed those by adding a semi colon but now I have this error:

    Assets/MouseHandler.cs(2,29): error CS0246: The type or namespace name `MonoBehaviour' could not be found. Are you missing a using directive or an assembly reference?

    it originally said monobehavior so i added in the u. now it says this still. I don't know how to fix that. I am aware that using Unity and using system will get rid of it but then there is a lot more errors after that
     
  46. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    add a ; at the end of line 57.
     
  47. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    pretty sure you meant line 55 and if so it causes this error

    Assets/MouseHandler.cs(1,28): error CS0246: The type or namespace name `MonoBehavior' could not be found. Are you missing a using directive or an assembly reference?
     
  48. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    lol, yeah, 55 is right. change MonoBehavior to MonoBehaviour.
     
  49. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    531
    I've did that.

    Assets/MouseHandler.cs(1,28): error CS0246: The type or namespace name `MonoBehaviour' could not be found. Are you missing a using directive or an assembly reference?
     
  50. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    I'm typing all of these on the fly only with notepad++, because I'm at work. So, I get lots of typos.