The Secret to Picking Up the Gnome in Community Garden

Being able to interact with objects is a key component to VR. Common player interactions include the ability to pick up objects, move objects around and set them back down. With previous versions of SpatialOS, implementing this was pretty easy. Unfortunately, with the latest version (V9) implementing these player actions isn't as straightforward. The code has become more flexible internally, but the documentation does not expose these new changes.

In previous versions, if a player wanted to pick up the gnome, a message would be sent from the player's entity to the gnome's entity to request ownership. The gnome would receive that message and handle the transfer of ownership to the player, allowing the player to move the gnome. I could not get this to work in Version 9 of Spatial OS, so I created a forum post to try to get some of my questions answered. 

After some back and forth with Improbable, I learned that I needed to modify the Entity's ACL when the player wanted control of the gnome. I tried to do this by building a new ACL which set the Player as the authority of the gnome using SetAcl(). Unfortunately, SetAcl() didn't seem to change the gnome's ACL. I tried to communicate this within my forum post and decided to create a simple fork of Improbable's PiratesTutorial Repo. I created a new branch and wrote some code with my current implementation. Check out my version of the PiratesTutorial.

Progress was still slow on the SpatialOS forums, so I tried a different approach. Instead of attempting to gain control of the gnome, I had the player send coordinates to the gnome's entity telling it where it wanted the gnome to move to. This worked but was not perfect and had one major issue with collision which you can read more about here.

Example of collision issue from alternative solution. Dropping the sphere in the planter should create a new plant but does not consistently.

Silly collision issues and still blank stares on my forum post...I was getting desperate at this point. I decided to make new post where I tried to explain my problem differently.

Eventually, the Improbable support team cloned my git repo and made some modifications. These changes revealed one major component I was missing. In SpatialOS, there is a concept of Readers and Writers in regards to an entity's state. With this new version of SpatialOS, it is required to use the new EntityAcl.Writer to make updates to the Entity's ACL. This allowed me to make the write access updates. Once I changed this, the player was able to take control of the gnome in the world.

Player can now pick up the the gnome.

I'm really glad this pesky gnome problem is out of the way. Not being able to interact with Community Garden's world would have really hurt player immersion. 

Update: I noticed this morning that Improbable forked my repo to help others work through similar problems. I happy to see the example being put to good use :) I think SpatialOS is easiest to under via example.