Log in or register to post comments

Error ModelTargetBehaviour.ModelTarget on iOS

December 22, 2020 - 2:15am #1

Hi,

I created the app that using model target and i managed to create a button to change the current guide view. The app works perfectly while i am working on PC and tested on Android.

But when i open the project on Mac and tested on Iphone, the apps has a bug. I checked it and found out the ModelTargetBehaviour.ModelTarget reference is null.

In editor, database and model target in ModelTargetBehaviour gameobject is set correctly even in Play Mode, it is not Empty.

 

This is my script to access the model target.

private ModelTargetBehaviour _modelTargetBehaviour;

private void Start()
{
 _modelTargetBehaviour= GetComponent<ModelTargetBehaviour>();
}

public void GuideView(int toggleId)
{
 if (_modelTargetBehaviour!= null)
 {
  ModelTarget modelTarget = _modelTargetBehaviour.ModelTarget;
  modelTarget.SetActiveGuideViewIndex(toggleId); //here is the error but only on iOS, modelTarget is null reference
 }
}

Error ModelTargetBehaviour.ModelTarget on iOS

February 27, 2021 - 5:20am #8

Damm even I am having a similar kind of issue, I have searched all over the internet and even have posted on number of threads on different forum, no solution seems to work. I am really frustrated, can anyone of you here help me resolve this issue, I am very much tired now. mx player

Error ModelTargetBehaviour.ModelTarget on iOS

January 12, 2021 - 5:47pm #7

Hi, 

I used Vuforia 6.9.3 and Unity 2019.4.7

I found this error occurs because my ModelTarget script used before the apps asks for camera permission at the first instalation. I resolve this by added new scene to request permission before enter AR scene.

Error ModelTargetBehaviour.ModelTarget on iOS

January 7, 2021 - 2:29am #6

Hi,

Could you please confirm the Vuforia Engine and Unity version?

Thank you.

Vuforia Engine Support

Error ModelTargetBehaviour.ModelTarget on iOS

January 5, 2021 - 10:25pm #5

Hi,

Apparently the error only occurs when it is first installed in iOS device. I don't know why.

Error ModelTargetBehaviour.ModelTarget on iOS

January 5, 2021 - 1:36am #4

Hi,

Ok, could you add your Model Target database to the Core sample app and let me know if you can cycle through the guideviews?

Thank you.

Vuforia Engine Support

Error ModelTargetBehaviour.ModelTarget on iOS

January 4, 2021 - 7:51pm #3

Thank you for the reply.

I tried the core sample but it has same error when i click CycleGuideView button.

The error in this line,

int activeView = modelTarget.GetActiveGuideViewIndex();

ModelTarget is NullReferenceException

Error ModelTargetBehaviour.ModelTarget on iOS

January 4, 2021 - 3:09am #2

Hi,

Its quite strange that it fails on iOS and works in PlayMode and Android.

In our Core Sample apps we demo how Model Targets and also cycle throught the guideview with following code:

/// <summary>

    /// Cycles through guide views for Standard Model Targets with multiple views.

    /// </summary>

    public void CycleGuideView()

    {

        VLog.Log("cyan", "CycleGuideView() called.");

        if (this.modelStandard != null)

        {

            ModelTarget modelTarget = this.modelStandard.ModelTarget;

            int activeView = modelTarget.GetActiveGuideViewIndex();

            int totalViews = modelTarget.GetNumGuideViews();

            if (totalViews > 1 && activeView > -1)

            {

                int guideViewIndexToActivate = (activeView + 1) % totalViews;

                VLog.Log("yellow",

                    modelTarget.Name + ": Activating Guide View Index " +

                    guideViewIndexToActivate.ToString() + " of " +

                    totalViews.ToString() + " total Guide Views.");

                modelTarget.SetActiveGuideViewIndex(guideViewIndexToActivate);

            }

            else

            {

                VLog.Log("yellow",

                    "GuideView was not cycled." +

                    "\nActive Guide View Index = " + activeView +

                    "\nNumber of Guide Views = " + totalViews);

            }

        }

    }

The code is available under ModelTargetManager.cs and the core sample are available through Unity Asset Store.

My advice would be to use our implementation as it works on iOS and Android.

Thank you.

Vuforia Engine Support

Log in or register to post comments