<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Raj Shirolkar on Medium]]></title>
        <description><![CDATA[Stories by Raj Shirolkar on Medium]]></description>
        <link>https://medium.com/@rajshirolkar?source=rss-463361785b42------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*pZH54WW9tGZYz-Ay.jpg</url>
            <title>Stories by Raj Shirolkar on Medium</title>
            <link>https://medium.com/@rajshirolkar?source=rss-463361785b42------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:26:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajshirolkar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Image Tracking with ARFoundation and Unity — Getting started]]></title>
            <link>https://rajshirolkar.medium.com/image-tracking-with-arfoundation-and-unity-getting-started-d17fed1a1309?source=rss-463361785b42------2</link>
            <guid isPermaLink="false">https://medium.com/p/d17fed1a1309</guid>
            <category><![CDATA[image-recognition]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[augmented-reality]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[cross-platform]]></category>
            <dc:creator><![CDATA[Raj Shirolkar]]></dc:creator>
            <pubDate>Thu, 19 Nov 2020 08:39:53 GMT</pubDate>
            <atom:updated>2020-11-19T08:39:53.596Z</atom:updated>
            <content:encoded><![CDATA[<h3>Image Tracking with ARFoundation and Unity — Getting started</h3><p>Image tracking is one of the most handy features in ARFoundation. We can use this feature to keep augmented anything and everything under the sun based on finding a unique image in the environment. Let’s see how we can do this.</p><p>Prerequisites :</p><ul><li>Unity 2020.2</li><li>Android device with ARCore support</li></ul><ol><li>Create a Unity Project and go to build setting -&gt; android -&gt; switch platform to android.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*0JqHlccej_0XCV8g6uPwSw.png" /></figure><p>2. Open the package manager and install the AR Foundation, ARCore XR Plugin and XR Plugin Management packages. Go to Player settings -&gt; XR Plugin Management -&gt; check the ARCore box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*bM0EOfpQZeMOlkM662Q4sA.png" /></figure><p>3. Now go to player settings and remove the Vulkan Graphics API as it is not supported and change the Minimum API level to Android 7.0 ‘Nougat ’ (API level 24)</p><p>4. Now in the scene remove the Main Camera and add the AR Session Origin and AR Session objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*1ocDLdt5ZeFru8bVq8ygYg.png" /></figure><p>5. In the ARSession object add the AR Tracked Image Manager script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*9qcIzBmYl0MZd5sy4o-rHw.png" /></figure><p>6. Now if you see, the AR Tracked Image manager script accepts a serialized library (we will check this out in depth in the next post) and a prefab to be instantiated when the image is detected. Now lets fill in these two by first creating a reference image library. Right click on assets -&gt; create -&gt; xr -&gt; reference image library</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*tmqZQJEEDMeXxtLIjQfnFg.png" /></figure><p>7. Lets add an image to this reference library which we want to track in the environment. You can specify the size of the image if you want to but it’s not mandatory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*0mrjD1Cmua1jziDF0udBCw.png" /></figure><p>8. Now we will need a script to control the tracking of images. Lets make an ImageTracker.cs script which looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*PD6FUQyS2Qj7-kSPUp-nrw.png" /></figure><p>Attach this script to the ARSession Gameobject.</p><p>Explainer -</p><ul><li>In this script whenever the gameobject this script is attached to is Awake() it will get the reference to the ARTRackedImageManager script we attached in step 5.</li><li>Whenever the object is enabled we fire start executing the OnImageChanged() function which loops through the event arguments and searches for our image using a foreach loop.</li><li>Once found we will simply log the name of the tracked image.</li><li>The OnDisable() method halts the tracking whenever the gameobject is disabled.</li></ul><p>9. Create a simple cube gameobject and set its scale to a reasonable value like 0.15 metres since we’ll be augmenting it in real world dimensions. Convert that gameobject into a prefab by dragging the cube into the assets directory.</p><p>10. So far we have :</p><ul><li>A serialized library containing the images we want to track</li><li>A Cube prefab which will be augmented on the image wherever the image is detected.</li><li>A ImageTracker.cs script attached to the ARSession Gameobject.</li></ul><p>Lets add these things into the AR Tracked Image Manager component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*POk0lSf1qyfXCpsNnR9Fpg.png" /></figure><p>11. Now build and run the project and point the camera to the image you want to track and we’re done with the basics!! In the next post we will take a deeper dive into how we can gain better control of the gameobject position for real world projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9j_4gUVJtITAcMPOeiz_XQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d17fed1a1309" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Async/Await in Unity]]></title>
            <link>https://rajshirolkar.medium.com/how-to-use-async-await-in-unity-3519434a43bb?source=rss-463361785b42------2</link>
            <guid isPermaLink="false">https://medium.com/p/3519434a43bb</guid>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[asyncawait]]></category>
            <category><![CDATA[async-functions]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Raj Shirolkar]]></dc:creator>
            <pubDate>Thu, 29 Oct 2020 07:14:07 GMT</pubDate>
            <atom:updated>2020-10-29T07:54:22.959Z</atom:updated>
            <content:encoded><![CDATA[<p>Async/Await is one of the most useful features in any programming language. In single threaded applications or applications like Unity where the UI runs on a single thread it is extremely useful for smooth functioning of the app to make Async calls which won’t block the main UI thread . We’ll get the whole code first so people who are frantically trying to solve the issues in their project can have a quick peek.</p><pre>using UnityEngine;<br>using System.Threading.Tasks;</pre><pre>public class TaskExample : MonoBehaviour<br>{<br>    float _elapsed = 0;<br>    void Start()<br>    {<br>        Debug.Log(&quot;Start begins&quot;);</pre><pre>        //Initialize a task completion source.<br>        //This will be our source for creating a task and also holding the result on it&#39;s completion.<br>        <br>var tcs = new TaskCompletionSource&lt;Vector3&gt;();<br>        Task.Run(async () =&gt;<br>        {<br>            Debug.Log(&quot;Task started&quot;);<br>            tcs.SetResult(await LongRunningTask());<br>            Debug.Log(&quot;Task stopped&quot;);<br>        });</pre><pre>// ConfigureAwait must be true to get unity main thread context<br>        tcs.Task.ConfigureAwait(true).GetAwaiter().OnCompleted(() =&gt;<br>        {<br>            Debug.Log(&quot;Task completed&quot;);<br>            transform.Rotate(tcs.Task.Result);<br>        });</pre><pre>Debug.Log(&quot;Start method ends&quot;);<br>    }</pre><pre>void Update()<br>    {<br>        if (_elapsed &gt; 1)<br>        {<br>            Debug.Log($&quot;Update loop running for : &quot; + Time.realtimeSinceStartup + &quot; seconds&quot;);<br>            _elapsed = 0;<br>        }<br>        _elapsed += Time.deltaTime;<br>    }</pre><pre>async Task&lt;Vector3&gt; LongRunningTask()<br>    {<br>        var rand = new System.Random();<br>        var v = Vector3.zero;<br>        // Do somethings that takes a long time<br>        for (var i = 0; i &lt; 30000000; i++)<br>        {<br>            v = new Vector3(rand.Next(0, 360), rand.Next(0, 360), rand.Next(0, 360));<br>        }<br>        return v;<br>    }<br>}</pre><p>Log :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*FHGW0RhXULPVjXOZl82Egg.png" /><figcaption>The logs depict the flow of the code as it excutes the async tasks.</figcaption></figure><p>Async/await in C# is similar to promises in javascript to some extent. The underlying concept is the same.</p><p>You create a task and send it to say fetch some data from the server. Next you set a means for our code to store the result of the task whenever it comes back with a response from the server.</p><p>In the above example we create a TaskCompletionSource which will provide us with a source to create the task and also a source to hold the result on the completion of the task.</p><pre>var tcs = new TaskCompletionSource&lt;Vector3&gt;();</pre><p>Create the Task :</p><pre>Task.Run(async () =&gt;<br>        {<br>            Debug.Log(&quot;Task started&quot;);<br>            tcs.SetResult(await LongRunningTask());<br>            Debug.Log(&quot;Task stopped&quot;);<br>        });</pre><p>Using the result of the task on completion</p><pre>// ConfigureAwait must be true to get unity main thread context<br>        tcs.Task.ConfigureAwait(true).GetAwaiter().OnCompleted(() =&gt;<br>        {<br>            Debug.Log(&quot;Task completed&quot;);<br>            transform.Rotate(tcs.Task.Result);<br>        });</pre><p>Here the LongRunningTask( ) method returns a Vector3 which dictates the rotation for our gameobject to which this script is attached. The result of the LongRunningTask( ) method can be accessed by the Task.Result property which we set in</p><pre>tcs.SetResult(await LongRunningTask());</pre><p>Now we need to create a function called LongRunningTask() which will be async and will return a Vector3 which dictates the rotation for our gameobject to which this script is attached.</p><pre>async Task&lt;Vector3&gt; LongRunningTask()<br>    {<br>        var rand = new System.Random();<br>        var v = Vector3.zero;<br>        // Do somethings that takes a long time<br>        for (var i = 0; i &lt; 30000000; i++)<br>        {<br>            v = new Vector3(rand.Next(0, 360), rand.Next(0, 360), rand.Next(0, 360));<br>        }<br>        return v;<br>    }</pre><p>Note : the return type is enclosed in Task&lt;&gt;. I made this mistake and spent a good 5 minutes wondering why I was getting an error.</p><p>Now in Unity Editor lets create a new scene and add a 3D Object of a capsule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1mGp15Wl-B5rVosTdRVCyg.png" /><figcaption>Create a capsule so we can see it rotate.</figcaption></figure><p>Now attach our script to this capsule and run! We can see the flow of the code in the logs and we can also see the capsule rotating in the scene.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3519434a43bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>