Your Game Should Acknowledge Your Player’s Actions : Unity’s XR Interaction Toolkit Affordance System for Dynamic Experiences

Have you ever played a game that lacked feedback? It can be the absolute worst! It’s a shame too, because some of these games could have been hits if they didn’t forget this one simple development tip. Your games should give feedback quickly and often! 

Can you pick up an item in this game? That should never be a question that comes to your audiences mind after they’ve played your game for at least an hour. By then, you should have established enough visual and audio cues that they know they can pick something up through the language of the feedback that you’ve established.

This tutorial will help you implement a scalable way to provide feedback to your users through the Unity XR Interaciton Toolkit Affordance System!

The VR Template can be found here!

the Affordance System

The Affordance System can be found in versions of the XR Interaction Toolkit from 2.3.2 and up. (This system will be deprecated after version 3.0 comes out). Although this system will be deprecated in the future, a date for the future replacement hasn’t been announced yet, so it’s still helpful to know how to use this system until it’s replacement is released!

The Affordance System is actually really easy to understand. We just need to have a XR Interactable Affordance State Provider. That State Provider can then coordinate with Audio, Color and Scale Receivers to control those aspects for our objects that we want our player to interact with. Finally, the Affordance Theme Assets are Scriptable Objects that will be used to store the data for the Receivers to use to change the colors, audio and scale of our objects.

adding The Affordance System

With the XR Interaction Toolkit installed do the following.

  • Use the search bar to find the “InteractionAffordance” prefab
  • Add this prefab to the GameObject you wish to add Affordance to
    • (The GameObject will need to be some form Interactable like a Grab or Ray Interactable)
  • Select the InteractionAffordance attached to the GameObject
    • Interactable Source = The GameObject it’s attached to

Taking note of some of the attributes of this component. We can adjust how long the transitions can take when changing between different states. We can also ignore certain events if we don’t want our GameObjects to change during certain state changes.

Affordance Receiver

If you expand the Interaction Affordance prefab, you’ll see that there is already a ColorAffordance attached to it. Let’s select it and see what it can do!

  •  Select the Color Affordance child object of the Interaction Affordance
    • Material Property Block Helper
      • Renderer = The Main GameObject’s Mesh Renderer
    • Color Material Property Affordance Receiver
      • Affordance State Provider = Interaction Affordance

 

 

This is specific to changing Colors, but if you want to do other things like Scale and Audio, you simply need to add a Scale or Audio Receiver components. 

This component will allow us to change the color of our game objects based on the current State of the GameObject and the Theme attached to it.

 

 

Affordance Themes

To see how the Theme works, double click InteractionColorAffordanceTheme found on the Color Material Property Affordance Receiver component.

You should be greeted with this! Which store all the data our Receiver will use to change the GameObject. This system of Scriptable Objects being used for the Affordance Themes allows us to make our interactions scalable and easily changed without having to change every individual GameObject. 

If you wish to make your own Theme, just do the following.

  •  Right click in Assets -> Create -> Affordance Theme -> (You needed theme for whatever Affordance Receiver you are using)

After that, you just fill out the data for the different states and how you want to them to change when interacting with your player.

Conclusion

The Affordance System is a great way to allow us to add more clear interactions for our players by reacting to their actions. It provides a scalable system that allows consistent change to all our objects through the use of Themes. We can also play with the Color, Scale and Audio of our objects as they change from different States.

As always, I hoped this helped and I’ll see you in the next one!