[Worlds] How to make any of your Worlds remember your settings?

Alternative Title: How to make any toggle save upon leaving or joining/rejoining?

I want to make it so my world remembers what you’ve toggled on or off. For example, I want to keep the media player toggled on, and always stay toggled on whenever I leave/rejoin the world.

I tried searching up tutorials on how to make a Udon script have this type of save feature, no luck. I tried to make it myself by adding Persistence events, didn’t work or I might had did something wrong.

Also, I’m not good at making scripts, so I have to rely on tutorials to guide me.

I see they have an example for a jump counter, that might be simple enough to re work into a toggle.

But yeah, I’m surprised there isn’t a persistent toggle script included, apply to an object that is the button, give it the object to toggle and a key name.

I’ve added the Player Object and Persistence components to three toggles. I haven’t tested it yet though.

Will this work?

When you add a PlayerObject component, what you’re doing is declaring that that object is a template. The original template will be disabled, and a fresh copy will be instantiated for every player in the instance. So if you have 20 players you’ll have 20 buttons. That’s probably not what you want for this use case, it’s more relevant if you’re building systems which attach game objects to players but that’s not what you’re doing here.

I would suggest using PlayerData for this application. PlayerData is a synced, persistent data store per player. Each player can individually use their own player data to set persistent values. They can also get the data from other players.

Applying playerdata to a simple toggle that you want to be persistent but not synced would look like:

When you want to change the value of the toggle:

  • Set a value in playerdata

When you want to receive changes from playerdata:

  • listen for the OnPlayerDataUpdated event
  • Check for the player it came from, branch to ensure you’re only listening to local player playerdata updates
  • Get playerdata value
  • Apply value to the world

I hope that helps! If you have any questions let me know.