Error when loading images from json file: too many targets only the first one is picked

0 votes
asked Jan 12, 2018 by gleneindr (220 points)

Hello,

I get an error when loading images from Json File 

Warning: too many targets in [images_targets.json], only the first one is picked!

UnityEngine.Debug:Log(Object)
EasyAR.EngineNative:Log(String)
EasyAR.EngineNative:ezarImageTarget_load(IntPtr, String, Int32, String)
EasyAR.EngineNative:ImageTarget_load(IntPtr, String, Int32, String)
EasyAR.ImageTarget:Load(String, Int32, String)

Below the content of my json file

{
  "images" :
  [
    {
      "image" : "aaa.png",
      "name" : "aaa"
    },
    {
      "image" : "bbb.png",
      "name" : "bbb"
    },
    {
      "image" : "ccc.PNG",
      "name" : "ccc"
    }
  ]
}

Please can you help me.

1 Answer

0 votes
answered Jan 13, 2018 by gleneindr (220 points)

I misunderstood how it works.

Now everything works by loading json through code like that:

void CreateTarget(string targetName, out SampleImageTargetBehaviour targetBehaviour)
        {
            GameObject Target = new GameObject(targetName);
            
            Target.transform.localPosition = Vector3.zero;
            targetBehaviour = Target.AddComponent<SampleImageTargetBehaviour>();
            
        }

        void Start()
        {
            SampleImageTargetBehaviour targetBehaviour;
            ImageTrackerBehaviour tracker = FindObjectOfType<ImageTrackerBehaviour>();

    

            // dynamically load all targets from json file
            var targetList = ImageTargetBaseBehaviour.LoadListFromJsonFile("images_targets.json", StorageType.Assets);
            foreach (var target in targetList.Where(t => t.IsValid).OfType<ImageTarget>())
            {

                CreateTarget(target.Name, out targetBehaviour);
                targetBehaviour.Bind(tracker);
                targetBehaviour.SetupWithTarget(target);
                targetBehaviour.Size = new Vector2(target.Size.x, target.Size.y);

}

}

Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...