Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[Error] AR Foundation - Issue while reading

Discussion in 'AR' started by param_appm, Feb 20, 2020.

  1. param_appm

    param_appm

    Joined:
    Jun 14, 2017
    Posts:
    41
    I am trying to add images dynamically in reference to the Image Library of ARfoundation Unity. I have a method to access gallery images from the iPhone.
    Code Snippet: http://bit.ly/38JYDOa

    So, I want to add this image to add to the reference image library and make this image an AR target image. For that, I wrote the below code.

    Code Snippet: http://bit.ly/32c9YEe

    But when I run my app in iPhone I get below error:

    System.InvalidOperationException: The texture must be readable to be used as the source for a reference image in UnityEngine.XR.ARFoundation.MutableRuntime.

    Is there any possible way to convert texture image readable for ARFoundation dynamically from gallery images of a phone.

    Thank you for your time and help.

    Regards,
    Paramjot Singh
     
  2. jbergs

    jbergs

    Joined:
    Feb 13, 2014
    Posts:
    26
    I'm running into this very same issue. Were you able to figure this out?
     
  3. jswy1992

    jswy1992

    Joined:
    Jun 19, 2019
    Posts:
    4
    I have the same issue? Can someone help to solve it.
     
  4. cutaiar

    cutaiar

    Joined:
    Sep 14, 2017
    Posts:
    2
    Is there any update on this? Running into the same thing.
     
  5. cutaiar

    cutaiar

    Joined:
    Sep 14, 2017
    Posts:
    2
    Hey guys, eventually I got around the issue. I didn't convert the texture dynamically, but I did find some things that might be useful. I used this code to find out which textures were even supported in the first place and add the image.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.XR.ARSubsystems;
    5. using UnityEngine.XR.ARFoundation;
    6. public class AddImageToTrackedImageLibrary : MonoBehaviour
    7. {
    8.  
    9.     public ARTrackedImageManager m_ARTrackedImageManager = null;
    10.  
    11.     public Texture2D imageToAdd = null;
    12.  
    13.     IEnumerator Start()
    14.     {
    15.         yield return new WaitForSeconds(5f);
    16.         Debug.Log("About to add image");
    17.         AddImage(imageToAdd);
    18.     }
    19.  
    20.     private void AddImage(Texture2D texture) {
    21.  
    22.         if (m_ARTrackedImageManager.referenceLibrary is MutableRuntimeReferenceImageLibrary mutableLibrary)
    23.         {
    24.             // List all supported texture formats
    25.             for (int i = 0; i < mutableLibrary.supportedTextureFormatCount;i++) {
    26.                 Debug.Log("Texture Format Supported: " + mutableLibrary.GetSupportedTextureFormatAt(i));
    27.             }
    28.            
    29.             var addImageJob = mutableLibrary.ScheduleAddImageJob(texture, texture.name, 0.05f);
    30.             Debug.Log("Added: " + texture.name + " to the reference library.");
    31.         }
    32.         else {
    33.             Debug.Log("Failed");
    34.         }
    35.     }
    36. }
    And I made sure to set the import settings for the image I was trying to add to use a format that was supported. I chose RGBA 32 bit.
     

    Attached Files:

  6. punikol

    punikol

    Joined:
    Jan 15, 2018
    Posts:
    4
    In the Texture you have to tick the box Read/Write enabled
     
  7. tomilobas

    tomilobas

    Joined:
    Jun 17, 2018
    Posts:
    1
    This worked for me thank you :D