Improving Accessibility in Unity Games – Part 2

In Part 2 of Improving Accessibility in Unity games, you’ll add support for motor and cognitive disabilities and add some options to help guide players. By Mark Placzek.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 6 of 6 of this article. Click here to view the first page.

Making a Slider to Adjust the Subtitle Duration

The SubtitlePrefab prefab has a simple component attached to it called DestroyTimer, which does exactly what it says. Currently, it’s hard-coded to remove the subtitle after three seconds, so you’ll need to change that to make it customizable.

Find and open DestroyTimer.cs script in the Project view of Assets/RW/Scripts.

DestroyTimer needs to ask the SettingsManager for the subtitle duration, so add this private variable to the top of the class:

private SettingsManager settingsManager;

Then add the following line of code at the beginning of Start:

settingsManager = GameObject.FindGameObjectWithTag("SettingsManager").GetComponent<SettingsManager>();

Here, you find and assign the SettingsManager instance to the variable you created previously when the game starts.

Following that, still in Start, you need to adjust the hard-coded 3.0f (3 seconds) in GameObject.Destroy with the value selected by the player in SettingsManager. The line of code should now read like this:

GameObject.Destroy(gameObject, settingsManager.subtitleDurationSelected);

All that’s left is to connect the slider’s label with the SettingsManager‘s subtitleDurationLabel variable.

Back in Unity, select SettingsManager in the Hierarchy. Use the drop-down arrows in the Hierarchy to drill down to the SubtitleDurationLabel in Canvas ▸ SettingsMenu ▸ SettingsPanel ▸ SubtitleDurationSettingComponent ▸ SubtitleDurationLabel.

Drag it over to the Subtitle Duration Label field slot in the Inspector and you’re done!

Click Play and adjust the subtitle duration in the Settings Menu to six seconds. Now you can marvel at your subtitles’ new enhanced longevity!

Subtitles with a longer duration

Saving the Settings

You’re almost done, but you have a few loose ends to tie up.

Another small but important adjustment you should make is saving and loading all the setting changes the player makes. No one wants to make the same setting changes every time they launch their game, but this is a particularly important consideration for those that need to adjust settings for accessibility.

This last part of the tutorial will walk you through setting up a save and load for one of your controls. The process will be essentially identical for all the controls, so you can finish the rest yourself.

Open up SettingsManager and navigate to SetFontType, the first method you created in this tutorial.

At the very end of this method, just before the final closing bracket, add this line of code:

SaveSettings("FontType", dropdownValue);

When the player adjusts the font, you want to save the value. To do it, you’ll need some code that will send the name of the setting and the customized value to a save method. So you’ll create that now.

Creating a Save Method

Ahh, but you already have a SaveSettings method. Two, in fact!

This is called method overloading, it’s identical to the duplicated PublishSubtitle method you created with the added Color argument.

Note: Method overloading allows a class to have more than one method with the same name, provided their argument lists are different. The different Settings Menu components send different data types. Overloading in this instance allows you to use the same method name to save, sending whatever data is presented as an argument.

In SettingsManager.cs, Add a new overload method to take an Int as an argument:

private void SaveSettings(string keyString, int intToSave)
{
    PlayerPrefs.SetInt(keyString, intToSave);
}

Player Preferences is a simple way to persist a data value using a string key so that you can retrieve it later.

You save the font the player selected using the key FontType. You’ll use that key to retrieve the saved setting when the game launches.

Head to LoadSettings and add the following under the existing code:

if (PlayerPrefs.HasKey("FontType"))
{
    int fontTypeInt = PlayerPrefs.GetInt("FontType");
    SetFontType(fontTypeInt);
    fontDropdown.value = fontTypeInt;
}
else
{
    SetFontType(0);
    fontDropdown.value = 0;
}

While you’re editing LoadSettings, also uncomment the block of code there. This will enable loading for all the other settings in the menu.

Note: You will see an error in the new code you added with the fontDropdown variable not yet existing. Don’t worry though, you’ll add that next :]

Saving Your Player Settings

The SettingsManager‘s Start calls LoadSettings, which executes when the player launches the game.

This code checks if the player preferences has a key FontType. If it does, that indicates that there is previously-saved data to reference. So you get the value from the player preferences and use the same method that the actual drop-down calls to set the value for your game.

Finally, you need to reflect the loaded data in the drop-down component in the Settings Menu. You’ll create that public variable in a moment.

If there’s no FontType in the player preferences, set the default value for the game and the Settings Menu drop-down component.

At the top of the SettingsManager class, add the public variable.

public Dropdown fontDropdown;

Return to Unity to wire up this variable. Click on the Settings Manager in the Hierarchy. Drag the Dropdown GameObject from Canvas ▸ SettingsMenu ▸ SettingsPanel ▸ FontStyleSettingComponent onto the Font Dropdown field slot in the Inspector.

Setting up the Dropdown component

That’s it! Click Play and, in the Settings Menu, select the Simple font from the drop-down. Now, restart the game. That setting should persist, even when testing it in the editor.

Persisted settings

Where to Go From Here?

Well done! this was a big tutorial to work through. Accessibility is not a small topic but hopefully, you saw that adding these features, even for a fully-developed game, is both possible and worthwhile.

You can download the final project using the Download Materials button at the top or bottom of this tutorial.

During your time here, you worked through improvements for people with sight, hearing, motor and cognitive disability.

Some of your accomplishments include:

  • Making huge improvements to the game’s subtitles with adjustable sizes, fonts, added color, closed captions and even adjustable speed.
  • Ensuring that players can control the game with just a keyboard.
  • Addressing customizable keybindings, giving the player control over the sensitivity of controls and banishing button-mashing mechanics.
  • Addressing complications with color and sound puzzles and other considerations regarding levels of cognitive skill.

Remember the Game Accessibility Guidelines Website too. There is a lot of very useful information to help you in your quest to improve accessibility in your games over there, so check out the full list page here.

Game accessibility starts with all these things, as they address a broad subset of disability. However, you can go farther! Are there any other accessibility features you’d like to learn about? Talk about it in the comments below.

Mark Placzek

Contributors

Mark Placzek

Author

Ben MacKinnon

Tech Editor

Aleksandra Kizevska

Illustrator

Sean Duffy

Final Pass Editor

Over 300 content creators. Join our team.