Skip to main content

Persistent Idle Game

Persistent Idle Game World Preview

This scene implements a simple idle game that uses PlayerData to save the points and auto-clicker count for each player.

Visit the Persistent Idle Game Example World using the persistence-beta branch to try it for yourself!

Persistent worlds break if you create them on the VRChat website. Instead, create instances directly in VRChat.

Using the Example

Load the scene and tweak the Udon values on the "IdleGame" object to your liking. Play the scene, click the button to collect cheese, buy auto-clickers, leave play mode, and observe that the values are saved under their respective keys in the ClientSim PlayerData window.

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 script is IdleGame.cs. It handles the gameplay, saving, and loading. The only other script, IdleGameButton.cs communicates the player's button click to the main script.

Whenever the player clicks the button, they gain one point. The script saves the points in PlayerData using the POINTS_KEY string value.

Similarly, when the player buys an auto-clicker, they gain one auto-clicker and lose points. The script saves the amount of autoclickers using the AUTOCLICKERS_KEY string value.

The script gives the player one point per second for every auto-clicker. The price of the auto-clickers is multiplied by a fixed amount for every purchased auto-clicker.

Reloading the scene loads the points and auto-clicker value using POINTS_KEY and AUTOCLICKERS_KEY and calculates the auto-clicker price.


Changelog

  • 0.0.2: Script tweaks: The code uses OnPlayerRestored to load player data