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;
}