Search Unity

How to fixed overlapping panel during run time in Unity and Vuforia

Discussion in 'Vuforia' started by nubhokage1991, Dec 15, 2017.

  1. nubhokage1991

    nubhokage1991

    Joined:
    Jun 28, 2017
    Posts:
    8
    Hello Unity and Vuforia developers! I am currently developing an application for our school to create a AR based information guide where the user will look for a image target (school & department logo) to display the information related to that logo. I have been successful in attaining the said feature of the app however there is one problem that has been bugging me for the last few weeks, the app have already distinguish different logo but my problem is the main panel (where buttons with functions are present) the main panel doesn't hide it just overlaps with the new panel. You can see the image for your reference https://drive.google.com/drive/u/2/folders/1v3azgiEesGc699JsjafggKhXJ1d4a_A-. I also have this code for everyone to inspect and tell me the problem. I just put the Update() because I think this is where my problem takes place I just don't know how to edit it. Thank you in advance!

    Code (CSharp):
    1. void Update()
    2.         {
    3.        
    4.             StateManager sm = TrackerManager.Instance.GetStateManager();
    5.             IEnumerable<TrackableBehaviour> tbs = sm.GetActiveTrackableBehaviours();
    6.             foreach (TrackableBehaviour tb in tbs)
    7.             {
    8.                 string name = tb.TrackableName;
    9.                 ImageTarget it = tb.Trackable as ImageTarget;
    10.                 Vector2 size = it.GetSize();
    11.                 Debug.Log ("Active image target:" + name + "  -size: " + size.x + ", " + size.y);
    12.                 if (name == "HTC_Logo2")
    13.                 {
    14.                
    15.                     btnPanel.gameObject.SetActive (true);
    16.                     txtScanning.text = "HTC Logo";
    17.                     txtHint.text = "FOUND";
    18.                     }
    19.                 if (name == "CETELogo")
    20.                 {
    21.                     cetePanel.SetActive (true);
    22.                     txtScanning.text = "CETE Logo";
    23.                     txtHint.text = "FOUND";
    24.                 }
    25.             }
    26.         }
     
  2. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    Hello @nubhokage1991

    Your code is only setting the game objects active on detection and never deactivating them. If you are only allowing the detection of one image at a time, an easy solution would be when you set one panel to be active, set the other to be inactive.
    For example:
    Code (CSharp):
    1. if (name == "HTC_Logo2")
    2.                 {
    3.              
    4.                     btnPanel.gameObject.SetActive (true);
    5.                     cetePanel.gameObject.SetActive (false);
    6.                     txtScanning.text = "HTC Logo";
    7.                     txtHint.text = "FOUND";
    8.                     }
    Thanks
     
  3. nubhokage1991

    nubhokage1991

    Joined:
    Jun 28, 2017
    Posts:
    8
    The overlapping panel is within the same image target. The main panel where the mission and vision located will display if the image target is displayed. When I pressed the mission&vision button its associated panel will display together with the information, however the main panel can still be seen. Ive made a function that when I pressed the mission vision button the main panel should be hidden but its does not work. Ive also tried your code but still nothing happens.
     
  4. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    When you are displaying your mission&vision panel, you should disable your main panel in the same block of code.
     
  5. nubhokage1991

    nubhokage1991

    Joined:
    Jun 28, 2017
    Posts:
    8
    How should I execute it? Actually i've made a function missionShow() and attached it to the mission&vision button as click event to close the main panel. But still the same result, can you show me how to close it inside the block of code? Thank you for your reply by the way.
     
  6. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    If you main panel is one of the panels in the Update() function shown above, this will be turned on every frame and thus overwrite you turning it off on a button press. I'd recommend moving that code from an Update function to an callback of some variety. The DefaultTrackableEventHandler.cs scripts provided with the Core Samples provides an example of this.

    This class implements the ITrackableEventHandler Interface and registers itself with the TrackableBehaviour. It then triggers the function OnTrackableStateChanged when a target is detected or lost. Using this method, you should be able to remedy the issue you're seeing.

    Script attached for reference, but also available within the Core Samples as mentioned.
     

    Attached Files:

  7. nubhokage1991

    nubhokage1991

    Joined:
    Jun 28, 2017
    Posts:
    8
    Thank you for the inputs. Actually, previously when I was starting this project all of my function and execution I placed it to the DefaultTrackableEventHandler script and it runs perfectly that's also because I've only put one image target. But now that I've placed 2(two) image targets I've seen this code and implemented it for the AR camera to display the information depending on the image target found. Anyways I'll give it a try and get back to you today. Thank you very much
     
    Vuforia-Strasza likes this.
  8. nubhokage1991

    nubhokage1991

    Joined:
    Jun 28, 2017
    Posts:
    8
    I have tried placing the said block of code into the DefaultTrackableEventHandler.cs and put it in a function called imageTarget() and place it on the OnFound() function of the DTEH but still no positive result. In any case can you try to look for a better solution for this and test it yourself? I really need a help on this one, Thanks!
     
  9. nubhokage1991

    nubhokage1991

    Joined:
    Jun 28, 2017
    Posts:
    8
    Hello Vuforia and Happy new year, first of all thank you for your time and sharing your knowledge to answer my question. I still can't find the proper way to execute a solution to the problem I am encountering, so I came up with a way to cheat it; by cheating means I turn the new panel into color black just to cover up or for the main panel to be invisible after pressing button. But still it will be a huge help you can, or someone from your team or colleagues that can help me resolve my problem. If ever you have a question or you want more details regarding this problem I am very much willing to give you the full details, once again thank you very much for your time. Best regards.