Loading Image Target from persistentdatapath [Android]

0 votes
asked Apr 15 by creartivity (200 points)
edited Apr 15 by creartivity

Hello!

I'm triyng to load target images from unity persistentdatapath. It works as expected in Unity Editor but does not work on Android Build. On android the behaviour is very strange, it sometimes works, but only for the fist app launch after installing it. Most times it doesn't work at all.

What i mean with doesnt work is:

- The image is present in persistentdatapath folder

- I can load it with other methods correcly (as image/sprite ecc)

- The target is instatiated correctly

- The target recognition does not work (only in build)

MY CODE (working with TargetOnTheFly sample)

private IEnumerator CreateInstantTarget(byte[] fileBytes, string targetID)
        {     

            string photoPath =   Path.Combine(Application.persistentDataPath + "/", targetID + ".jpg");
           //CACHE IF NOT EXISTS
            if (!File.Exists(photoPath))
            {
                File.WriteAllBytes(photoPath, fileBytes);
                Debug.Log("Instant Target cached");
            }

            yield return new WaitForEndOfFrame();

            CreateImageTarget(targetID, photoPath);
        }

        private void CreateImageTarget(string targetName, string targetPath)
        {
            GameObject imageTarget = new GameObject(targetName);
            currentActiveTargets.Add(imageTarget);
            var controller = imageTarget.AddComponent<ImageTargetController>();
            controller.ImageFileSource.Scale = 1;
            controller.SourceType = ImageTargetController.DataSource.ImageFile;
            controller.ImageFileSource.PathType = PathType.Absolute;

           controller.ImageFileSource.Path = "file://" + targetPath;

            Debug.Log("LOADING PATH: " + controller.ImageFileSource.Path);

            controller.ImageFileSource.Name = targetName;
            controller.Tracker = Filter;

            controller.TargetFound += Controller_TargetFound;
            controller.TargetLost += Controller_TargetLost;        
        }

Please log in or register to answer this question.

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