How to show progress of an operation while it takes time to complete it?

I am looking to save Worldmap.I dont know much time it will take .I would like to show the progress.I tried AsyncOperation but not working.AsyncOperation async=session.GetCurrentWorldMapAsync(OnWorldMap) ; //error

 StartCoroutine(SaveProgress());

IEnumerator SaveProgress()
    {
        yield return null;

       //Whle the function is being done show the progress
       // Debug.Log("Progress");
       session.GetCurrentWorldMapAsync(OnWorldMap) ;
    }

example is in the manual, as always, so I call RTFM

1 Like

You read the first Line…AsyncOperation async=session.GetCurrentWorldMapAsync(OnWorldMap) ;…It is not working…y?..RTFQ… :slight_smile:

async is a reserved keyword in C#. Try calling it something else.

Thats not the error i believe…I have used asynOperation…but no luck… Error CS0029: Cannot implicitly convert type ‘void’ to ‘UnityEngine.AsyncOperation’

The method GetCurrentWorldMapAsync returns void. Not a async operation. What’s the signature of the delegate that the method takes as argument?

When I right clicked and went for declaration part…

public void GetCurrentWorldMapAsync(Action<ARWorldMap> completionCallback)
        {
            if (completionCallback == null)
                return;

#if !UNITY_EDITOR && UNITY_IOS
            GCHandle handle = GCHandle.Alloc(completionCallback);
            session_GetCurrentWorldMap(m_NativeARSession, GCHandle.ToIntPtr(handle));
#else
            // Not supported: Invoke user callback immediately with null ARWorldMap
            completionCallback(null);
#endif
        }

Does the ArWorld have loading progress, async operation etc?

Edit: ah it’s not supported it first called on conpletion

So with that method you cant get progress during load

You mean the ARWorldMap?

public class ARWorldMap
    {
        IntPtr m_Ptr;

        public static bool supported
        {
            get
            {
                return worldMap_GetSupported();
            }
        }

        public bool Save(string path)
        {
            return worldMap_Save(m_Ptr, path);
        }

        public static ARWorldMap Load(string path)
        {
            var ptr = worldMap_Load(path);
            if (ptr == IntPtr.Zero)
                return null;

            return new ARWorldMap(ptr);
        }

        public static ARWorldMap SerializeFromByteArray(byte[] mapByteArray)
        {
            long lengthBytes = mapByteArray.LongLength;
            GCHandle handle = GCHandle.Alloc (mapByteArray, GCHandleType.Pinned);
            IntPtr newMapPtr = worldMap_SerializeFromByteArray(handle.AddrOfPinnedObject(), lengthBytes);
            handle.Free ();
            return new ARWorldMap (newMapPtr);
        }

        public byte [] SerializeToByteArray()
        {
            byte[] worldMapByteArray = new byte[worldMap_SerializedLength(m_Ptr)];
            GCHandle handle = GCHandle.Alloc (worldMapByteArray, GCHandleType.Pinned);
            worldMap_SerializeToByteArray(m_Ptr,handle.AddrOfPinnedObject());
            handle.Free ();
            return worldMapByteArray;
        }

        public Vector3 center
        {
            get
            {
                return UnityARMatrixOps.GetPosition(worldMap_GetCenter(m_Ptr));
            }
        }

        public Vector3 extent
        {
            get
            {
                return worldMap_GetExtent(m_Ptr);
            }
        }

        public ARPointCloud pointCloud
        {
            get
            {
                return ARPointCloud.FromPtr (worldMap_GetPointCloud (m_Ptr));
            }
        }

        internal IntPtr nativePtr { get { return m_Ptr; } }

        internal static ARWorldMap FromPtr(IntPtr ptr)
        {
            if (ptr == IntPtr.Zero)
                return null;

            return new ARWorldMap(ptr);
        }

        internal ARWorldMap(IntPtr ptr)
        {
            if (ptr == IntPtr.Zero)
                throw new ArgumentException("ptr may not be IntPtr.Zero");

            m_Ptr = ptr;
        }

#if !UNITY_EDITOR && UNITY_IOS
        [DllImport("__Internal")]
        static extern bool worldMap_Save(IntPtr worldMapPtr, string path);

        [DllImport("__Internal")]
        static extern IntPtr worldMap_Load(string path);

        [DllImport("__Internal")]
        static extern Vector3 worldMap_GetCenter(IntPtr worldMapPtr);

        [DllImport("__Internal")]
        static extern Vector3 worldMap_GetExtent(IntPtr worldMapPtr);

        [DllImport("__Internal")]
        static extern IntPtr worldMap_GetPointCloud(IntPtr worldMapPtr);

        [DllImport("__Internal")]
        static extern bool worldMap_GetSupported();

        [DllImport("__Internal")]
        static extern long worldMap_SerializedLength(IntPtr worldMapPtr);

        [DllImport("__Internal")]
        static extern void worldMap_SerializeToByteArray(IntPtr worldMapPtr, IntPtr serByteArray);

        [DllImport("__Internal")]
        static extern IntPtr worldMap_SerializeFromByteArray(IntPtr serByteArray, long lengthBytes);
#else
        static bool worldMap_Save(IntPtr worldMapPtr, string path) { return false; }
        static IntPtr worldMap_Load(string path) { return IntPtr.Zero; }
        static Vector3 worldMap_GetCenter(IntPtr worldMapPtr) { return Vector3.zero; }
        static Vector3 worldMap_GetExtent(IntPtr worldMapPtr) { return Vector3.zero; }
        static IntPtr worldMap_GetPointCloud(IntPtr worldMapPtr) { return IntPtr.Zero; }
        static bool worldMap_GetSupported() { return false; }
        static long  worldMap_SerializedLength(IntPtr worldMapPtr) { return 0; }
        static void worldMap_SerializeToByteArray(IntPtr worldMapPtr, IntPtr serByteArray) { }
        static IntPtr worldMap_SerializeFromByteArray(IntPtr serByteArray, long lengthBytes) { return IntPtr.Zero; }
#endif
    }

It seems it does not give you a entry point to read the progress

1 Like

Have u tried ARworldMap example scene in unity?

No, just looking on what you supplied