Skip to main content

Unlock Items

Unlock Items World Preview

How to persistently unlock items using PlayerData, using simple in-world achievements as a demo.

Visit the Unlock Items Example World to try it for yourself!

Using the Example

  1. Enter the world
  2. Perform actions to unlock achievements
    • Spend time in the world (10sec,2min, 5min)
    • Move around (10 units, 100 units, 300 units)
    • Respawn
    • Find the secret
    • All of the above
  3. Observe the UI showing your unlocked achievements
  4. Leave and return - your achievements and stats (time spent in world, distance travelled) should persist

Importing the Example

Follow the steps below to add this example to your Unity project:

  1. Open the Example Central Window from the window from the Unity Editor Menu under "VRChat SDK > 🏠 Example Central"
  2. Find this prefab in the list or search for it by title (same as the title of this page).
  3. Press the "Import" button to import the Unitypackage into your project.

Technical Breakdown

The main UnlockItems script checks for the local player's achievements when their data first loads in during the OnPlayerRestored method, and restores all the unlocked items that are found.

It then triggers the UpdateStats method to run, which runs the following methods:

  • CheckTimeInWorld();
  • CheckDistanceMoved();
  • CheckHasPlayerRespawned();
  • CheckHasFoundSecret();
  • CheckAllAchievementsUnlocked();

After all methods are run and achievements updated, this method calls itself to run again after a delay of UPDATE_STATS_TIME.

For each achievement that is unlocked during the UpdateStats check, the UnlockAchievement method is called, which updates the sprite, color and text of the target achievement.