<?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 Grant Jarvis on Medium]]></title>
        <description><![CDATA[Stories by Grant Jarvis on Medium]]></description>
        <link>https://medium.com/@realitydev?source=rss-ecb8c2f9a717------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6YTlZHFpscmIcSEL</url>
            <title>Stories by Grant Jarvis on Medium</title>
            <link>https://medium.com/@realitydev?source=rss-ecb8c2f9a717------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 00:05:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@realitydev/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[RealityKit: Easier Collision Groups]]></title>
            <link>https://realitydev.medium.com/realitykit-easier-collision-groups-818b07508c4c?source=rss-ecb8c2f9a717------2</link>
            <guid isPermaLink="false">https://medium.com/p/818b07508c4c</guid>
            <category><![CDATA[collision]]></category>
            <category><![CDATA[arkit]]></category>
            <category><![CDATA[augmented-reality]]></category>
            <category><![CDATA[realitykit]]></category>
            <category><![CDATA[ios-development]]></category>
            <dc:creator><![CDATA[Grant Jarvis]]></dc:creator>
            <pubDate>Fri, 12 Mar 2021 20:18:18 GMT</pubDate>
            <atom:updated>2021-03-13T02:47:08.162Z</atom:updated>
            <content:encoded><![CDATA[<h4>An easier way to determine what collides with what.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Ch5hBLD4VbqV6W6Diu1fhA.gif" /></figure><h3>An Easier Way</h3><p>What if we wanted to determine which entities could collide with one another, and which ones could not? If you have ever tried to make your own CollisionGroups in RealityKit, you know it deals with creating your own bitMasks with 32 bits each and making sure that they don’t intersect in ways that you don’t want.</p><p>When you want to do more customization than simply having every entity collide with everything, this can become difficult, so I make a swift package to make this process easier.</p><p><a href="https://github.com/Reality-Dev/RealityKit-Collisions">Reality-Dev/RealityKit-Collisions</a></p><p>This allows you to set collision groups as easy as this:</p><pre><strong>setNewCollisionFilter</strong>(thisEntity: alienEntity,</pre><pre>belongsToGroup: .aliens,</pre><pre>andCanCollideWith: [.aliens, .bigRubbberBall, .ground])</pre><p>You can define your own custom collision groups like this, with up to 32 different groups:</p><pre>public enum MyCustomCollisionGroups: String, CaseIterable {</pre><pre><strong>case</strong> teammates, aliens, bigRubbberBall, ground<br><strong>case</strong> customCollisionGroup3, customCollisionGroup4</pre><pre>}</pre><p>See the package’s ReadMe for more details.</p><p><a href="https://www.youtube.com/watch?v=Pit-Dn8WvN8"><strong>This YouTube video</strong></a> shows the steps in practice.</p><h3>LiDAR</h3><p>If you are using a LiDAR-enabled device, you might want your entities to collide with the scene mesh. You could call addCollisionWithLiDARMesh(on: myEntity) , or you could add “sceneMesh” to the MyCustomCollisionGroupsenum.</p><p>This is how you check if the user is on a LiDAR-enabled device:</p><pre><strong>if</strong> ARWorldTrackingConfiguration.supportsSceneReconstruction(.mesh) {</pre><pre>}</pre><h3>Collision Listening</h3><p>If you want to run code when collision events occur, then you can use this function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/542d92252addb4210bd6b7c2e6a2dc06/href">https://medium.com/media/542d92252addb4210bd6b7c2e6a2dc06/href</a></iframe><p>Then you can call this function like this: addCollisionListening(onEntity: myEntity)</p><p>I hope this saves you some time and helps you out!! Please give this article a few claps if it did!👏🏽👏🏽👏🏽</p><p>If something is confusing or isn’t working please send me a message on <a href="http://twitter.com/gmj4k">Twitter</a> or leave a comment on this article. Cheers! 🍻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=818b07508c4c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS 14 RealityKit — Why Your Multiplayer AR App is Breaking.]]></title>
            <link>https://realitydev.medium.com/ios-14-realitykit-why-your-multiplayer-ar-app-is-breaking-9335df79bcdb?source=rss-ecb8c2f9a717------2</link>
            <guid isPermaLink="false">https://medium.com/p/9335df79bcdb</guid>
            <category><![CDATA[augmented-reality]]></category>
            <category><![CDATA[realitykit]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[arkit]]></category>
            <category><![CDATA[ar]]></category>
            <dc:creator><![CDATA[Grant Jarvis]]></dc:creator>
            <pubDate>Fri, 25 Sep 2020 03:22:58 GMT</pubDate>
            <atom:updated>2020-09-26T14:16:42.351Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>iOS 14 RealityKit — Why Your Multiplayer AR App is Breaking.</strong></h3><h4>Terminating app due to uncaught exception</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qGD9eSBbD7OFcR4qIlAgKw.png" /></figure><p>If you are like me, you thought one of the most exciting new announcements at WWDC 2019 was Collaborative Session — a way for developers to create shared AR experiences between people in the same space.</p><p>The Collaborative Session feature provides you with collaboration data, but requires you to select and implement a service for networking that data on your own. One of the most convenient (and free) networking services to use for this purpose is Multipeer Connectivity — a framework made by Apple for communicating with nearby devices.</p><p>If you had a multi-user AR app for iOS 13 or older and you recently upgraded to iOS 14, you’ll notice that your app no longer works anymore. When you run the app it will likely crash and give you an error such as:</p><p><strong><em>Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[Demoapp.MultipeerSession browser:didNotStartBrowsingForPeers:]: unrecognized selector sent to instance 0x283818780&#39;</em></strong></p><h3>Why does this happen?</h3><ul><li>Because Apple likes security and privacy.</li><li>(Also: more on checking the RealityKit compatibility between the devices below).</li></ul><p>Apple would rather have the user have to give you explicit permission to access their local network, just like the user has to explicitly give permission for you to access bluetooth capabilities or the device’s camera and microphone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Dh1ufuELvS9KYGRUtBDLuw.png" /></figure><p>You can also find this permission in the settings app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*GENl7yHV7J6EIiDmG1_evA.jpeg" /></figure><h3>So how do we make this request pop-up happen?</h3><p>We need to add two entries to our info.plist file:</p><ul><li>Privacy — Local Network Usage Description, and</li><li>Bonjour Services</li></ul><p><strong>The first one is relatively straightforward</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*So4lmmLxqxkHcLmXhYLkpw.gif" /><figcaption>Network Usage Request</figcaption></figure><p>Add the Privacy-Local Network Usage Description to your property list. In the Value column, Make sure to give an easy-to-understand usage description to the user, such as this one: “This app uses the local network to connect with players nearby”</p><p><strong>The second entry (Bonjour Services) is a bit more complicated</strong>:</p><p>First, we need to do something similar by adding a new key to our info.plist file, but this time it is called Bonjour Services. This is an array of strings declaring which Bonjour Service Types we would like to use. We need to insert two strings into this array, which we will find next.</p><p>(For those who have not created an app with Multipeer Connectivity before, you can find a nice tutorial on this <a href="https://www.youtube.com/watch?v=D1NhwmDUhYU&amp;t=1224s">here</a>)</p><p>To find your strings, you must know the <strong>service type</strong> of your multipeer session object. The service type is a String that is used when you initialize your MCNearbyServiceBrowser like this:</p><ul><li>MCNearbyServiceBrowser(peer: myPeerID, <strong>serviceType</strong>: MultipeerSession.serviceType)</li></ul><p>In my case, my service type is the String “demoapp”. Notice how the error we got earlier was related to <em>browsing</em> for peers.</p><p>Now that we know our service type name, we can make the entries like this:</p><p>_demoapp._tcp</p><p>_demoapp._udp</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*HBBw6WHOnudhtj6gjZZygw.gif" /><figcaption>Adding Bonjour Services</figcaption></figure><p><strong>To elaborate on this further</strong>:</p><p>For the first one: add one underscore to the beginning of your service type name “_”, and then add “._tcp” to the end of it.</p><p>For the second one: add one underscore to the beginning of your service type name “_”, and then add “._udp” to the end of it.</p><p>Your strings will likely not include the <em>demoapp </em>part, since you will insert your own service type there.</p><p>If you are more interested in what these mean: <strong>Tcp</strong> and <strong>udp</strong> are names that specify which <strong>transport protocols</strong> our service is using. We are making <strong>registration types </strong>(to insert into the Bonjour services in our info.plist) by combining those transport protocol names with our service type and the underscores &amp; period. <em>i.e.</em> This is the format for registration types: <em>_ServiceType._TransportProtocolName</em></p><p>You can find more information on the naming <a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/NetServices/Articles/domainnames.html">here</a>.</p><h3>Voilà!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*BtKH-u154q007rRosQfM7g.png" /></figure><h3>Making a better User Experience</h3><p>Right now, however, this is quite a jarring experience for our users, since our app asks for permission as soon as they open it.</p><p>Wouldn’t it be better for the app to ask for permission only when we needed to begin using the networking service? To do this, simply initialize your MCNearbyServiceBrowser (or whatever object is creating this for you) only whenever your app is ready to begin looking for other devices. Then the pop-up will occur at this point. This could be after the user presses a button labeled “Start Multiplayer” or after any other event that you would like. The user only needs to give permission the first time they use the app and afterwards this setting is saved.</p><h3>What else is breaking my app?</h3><p>I hope this saved you some time!! I was pretty confused when I first got these errors truth be told. If you felt like this article helped you please let me know by clapping it up (members can clap up to 50 times per article) and leaving any comments you have.</p><p>Another thing that could be causing your multiplayer AR app to fail is having devices that are running <a href="https://medium.com/@realityDev/multiplayer-ar-with-realitykit-what-went-wrong-36e8f90f8b70"><strong>incompatible versions of RealityKit</strong></a>. Lucky for us, Apple has provided a way for us to check to see if the devices are compatible, which I explain over in *<a href="https://medium.com/@realityDev/multiplayer-ar-with-realitykit-what-went-wrong-36e8f90f8b70"><strong>this article</strong></a>* for you guys. Cheers!! 🍻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9335df79bcdb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multiplayer AR with RealityKit — What Went Wrong??]]></title>
            <link>https://realitydev.medium.com/multiplayer-ar-with-realitykit-what-went-wrong-36e8f90f8b70?source=rss-ecb8c2f9a717------2</link>
            <guid isPermaLink="false">https://medium.com/p/36e8f90f8b70</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[augmented-reality]]></category>
            <category><![CDATA[ar]]></category>
            <category><![CDATA[arkit]]></category>
            <category><![CDATA[realitykit]]></category>
            <dc:creator><![CDATA[Grant Jarvis]]></dc:creator>
            <pubDate>Fri, 25 Sep 2020 03:18:36 GMT</pubDate>
            <atom:updated>2020-12-18T16:04:13.750Z</atom:updated>
            <content:encoded><![CDATA[<h3>Multiplayer AR with RealityKit — What Went Wrong??</h3><h4>Are you seeing what I’m seeing?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j-ytu3Ka_yZPBFhn_vuDzA.png" /></figure><p>Augmented Reality on its own can be a great experience and a powerful tool, but it is so much better when you can share the experience with other people at the same time. If you would like to work on building a Multiplayer AR app with RealityKit, one thing you will need to check for is if the versions of RealityKit are compatible.</p><p>(If you have never worked on an AR app with Multipeer Connectivity before, you can find a nice tutorial on how to do this <a href="https://www.youtube.com/watch?v=D1NhwmDUhYU&amp;t=1224s">here</a>. This article covers important topics which are not covered in that tutorial.)</p><h3>Sharing ARAnchors</h3><p>There is a difference between <strong>sharing ARAnchors</strong> and <strong>having network synchronization</strong>. I bring this up because you need to check for compatibility when using network synchronization, but <em>not</em> when just sharing ARAnchors. By the end of this article, I anticipate you will want to use network synchronization as well (and therefore check for compatibility). Let’s see why:</p><p>Apple defines ARAnchors as “A position and orientation of something of interest in the physical environment.” This means the anchor represents the position and orientation of something in the <em>real-world</em> environment which we are tracking, so that we can attach virtual content to it. When you are sharing CollaborationData in a Collaborative Session, you are sharing ARAnchors. Sharing ARAnchors means both devices know where they are in space relative to one another (with ARParticipantAnchor), and both devices agree on where any ARAnchors placed into the scene are. You cannot actually see these anchors unless you insert:</p><p>arView.debugOptions.insert(.showAnchorOrigins)</p><p>In RealityKit, “Entities” includes the 3D objects in your scene that you can <strong><em>see</em></strong> — that kind of entity is called a ModelEntity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*9iPT50wia2MUMat0loTaQg.png" /></figure><p>You <em>can</em> see virtual objects that you <em>attach</em> to the ARAnchors.</p><p>(More specifically you would make an AnchorEntity from the ARAnchor with <strong>let</strong> anchorEntity = AnchorEntity(anchor: ARAnchor) and then add the ModelEntity as a child to that AnchorEntity. You could alternatively make an AnchorEntity that targets a type of ARAnchor with <strong>let</strong> anchorEntity = AnchorEntity(.plane(.horizontal, classification: .any, minimumBounds: .zero) and add your ModelEntity as a child to that AnchorEntity with anchorEntity.addChild(modelEntity))</p><p>You can even attach entities to ARParticipantAnchors and have the entities move around as if they were attached to the other device:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*G-rQBia1Hq4E-HGzod_8AQ.gif" /><figcaption>ARParticipantAnchor demonstration</figcaption></figure><p>Sharing ARAnchors does not mean, however, that any interaction with entities will be visible on both devices. i.e. I can add an identical-looking sphere to the same ARAnchor on both devices, and this gives the illusion of multiplayer, but these are actually two <em>different</em> spheres. As long as you programmatically make them both move the same way, they will appear to be the same sphere, but they are not the same sphere. <strong>This the type of “<em>multiplayer</em>” that is being used in </strong><a href="https://developer.apple.com/documentation/arkit/creating_a_collaborative_session"><strong>this sample app from Apple</strong></a><strong>, and in the tutorial I previously linked to</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*SXtUh_m1Lz6380aXlfYjCQ.gif" /><figcaption>NOT the same sphere</figcaption></figure><p>As soon as you incorporate dynamic physics:</p><p>myModelEntity.physicsBody.mode = .dynamic</p><p>Or collisions, user interaction (such as dragging the object around, adjusting its scale/size, rotating it), <strong>you are likely to see the two spheres move and behave in <em>different</em> ways</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*aCYIe9fYHXStxgNjlkFBlg.gif" /><figcaption>NOT the same sphere</figcaption></figure><p>If you want to make a true multiplayer app, you want your entities to be able to interact with my entities. i.e. If we were making a <strong>multiplayer AR 8-Ball / Pool game</strong>, I want to be able to strike the same pool balls that you strike and have us both watch the same pool balls do the same thing.</p><p>So how do we make both devices see the <em>same</em> entities and see them move and behave in the <em>same</em> ways? When you are sharing Collaboration Data in a Collaborative Session, you are sharing ARAnchors, but we need to *<strong><em>also* </em></strong>include network synchronization on top of this.</p><h3>Making Network Synchronization</h3><p>You will actually notice that Apple includes synchronization components by default on all of your entities. This component is used to synchronize an entity between devices so that it looks and behaves the same on each of them.</p><p><strong>As a side note</strong>: In their sample apps which are <strong><em>not</em></strong> multiplayer, Apple programmatically <strong><em>removes</em></strong> those synchronization components to save memory, and I suggest that you do the same on <strong><em>non</em></strong>-multiplayer apps.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07816c8398d276e63e8b7a4be64bc7b5/href">https://medium.com/media/07816c8398d276e63e8b7a4be64bc7b5/href</a></iframe><p>Then you can call myEntity.removeSynchronizationComponents() and it will remove the Synchronization Component on that entity and all of its children (I recommend calling this method on Anchor Entities since this most easily covers all of the entities in your scene).</p><p>But for apps that <strong><em>are</em></strong> local multiplayer, you clearly would want to leave these components attached. So how do we make use of those components? Some swift packages do not set up synchronization and checking compatibility automatically for you. If yours does not, we must assign something to be our scene’s synchronizationService, like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8aa684682dc01c1abc110905d16163e1/href">https://medium.com/media/8aa684682dc01c1abc110905d16163e1/href</a></iframe><p>Keep in mind: if you are using a swift package to set up your Multipeer Connectivity Session, you may need to edit it in order to access the session variable. To do edit the package, you will need to make it part of your main bundle.</p><p>Also, make sure your session’s configuration has <strong>isCollaborationEnabled</strong> set to <strong>true</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3e027daae2589db79dc252abac73ceb/href">https://medium.com/media/a3e027daae2589db79dc252abac73ceb/href</a></iframe><p>The version of RealityKit running on the device comes bundled with whatever version of iOS that the device is running. So having the wrong match-up of iOS versions can make this synchronization not work.</p><p>To make the comparison, you need to send your local NetworkCompatibilityToken to the other device, and handle the NetworkCompatibilityToken coming from the other device. We will encode our local token into our discoveryInfo array, which theMCNearbyServiceAdvertiser below will automatically send to the other device for us.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfce2dfc3f185b28ef0dc6394da8319a/href">https://medium.com/media/cfce2dfc3f185b28ef0dc6394da8319a/href</a></iframe><p>When you make your MCNearbyServiceAdvertiser , pass in this discovery info.</p><p>serviceAdvertiser = MCNearbyServiceAdvertiser(peer: myPeerID, discoveryInfo: <strong>discoveryInfo</strong>, serviceType: serviceType)</p><p>Now for the<strong> incoming data</strong> from the other device:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54f36b6ba731d85eb42bef4826822cc3/href">https://medium.com/media/54f36b6ba731d85eb42bef4826822cc3/href</a></iframe><p>One of the best places to call this checkCompatibility() function is inside of this delegate function:</p><p><strong>public</strong> <strong>func</strong> browser(<strong>_</strong> browser: MCNearbyServiceBrowser, foundPeer peerID: MCPeerID, withDiscoveryInfo info: [String: String]?) {}</p><h3>Here We Go!!</h3><p>I hope this article helped clear things up for you! If you felt like this article was beneficial please let me know by clapping it up (members can clap up to 50 times per article) and leaving any comments you have. You might also like my article on <a href="https://medium.com/@realityDev/ios-14-realitykit-why-your-multiplayer-ar-app-is-breaking-9335df79bcdb"><strong>why your multiplayer AR App is breaking</strong></a> which goes into further detail about asking for permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*VSTuG31NcrP9XZx8B15Xfw.gif" /><figcaption>Multiplayer with Synchronization</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36e8f90f8b70" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>