Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be 📖

PlayerPrefs

An asset by Kshitij
The page banner background of a mountain and forest
PlayerPrefs thumbnail image
PlayerPrefs thumbnail image
PlayerPrefs thumbnail image
PlayerPrefs thumbnail image
PlayerPrefs hero image

Quick Information

0 ratings
PlayerPrefs icon image
Kshitij
PlayerPrefs

Save player preferences in-game similar to other game engines. This is a simple class that allows you to save and load data in a file. It is very easy to use and it is very useful for saving game data.** New **- Add an editor option to check saved Preferences.- Add pref change/set signal.

Supported Engine Version
4.1
Version String
0.2
License Version
MIT
Support Level
community
Modified Date
1 year ago
Git URL
Issue URL

PlayerPrefs

Description

This is a simple class that allows you to save and load data in a file. It is very easy to use and it is very useful for saving game data.

README Alt text

How to use

Save data


# Save individual data
func save_player():
    PlayerPrefs.set_pref("no", 1)
    PlayerPrefs.set_pref("name", "godot")
    PlayerPrefs.set_pref("crosshair_position", Vector2(1, 2))
    PlayerPrefs.set_pref("player_position", Vector3(1, 2, 3))
    PlayerPrefs.set_pref("random_info", Vector4(1, 2, 3, 4))
    PlayerPrefs.set_pref("color", Color(1, 2, 3, 4))
    PlayerPrefs.set_pref("item_rect", Rect2(1, 2, 3, 4))

# Save complete information
func set_player_base():
    var player = {"no": 1, 
        "score": 0,
        "crosshair_position": Vector2(1, 2),
        "player_position": Vector3(1, 2, 3),
        "random_info": Vector4(1, 2, 3, 4),
        "color": Color(1, 2, 3, 4),
        "item_rect": Rect2(1, 2, 3, 4)}
    
    PlayerPrefs.set_base(player)

Signal for save data

When ever preferences are changed, it will emit a signal. To listen to the signal, use the following code.

PlayerPrefs.prefs_changed.connect(_on_prefs_changed)

func _on_prefs_changed(key, value):
    print("Prefs changed:- ", key, " : ", value)

Load data


# Load individual data
func get_player():
    PlayerPrefs.get_pref("no", 0)
    PlayerPrefs.get_pref("name", "")
    PlayerPrefs.get_pref("crosshair_position", Vector2(0, 0))
    PlayerPrefs.get_pref("player_position", Vector3(0, 0, 0))
    PlayerPrefs.get_pref("random_info", Vector4(0, 0, 0, 0))
    PlayerPrefs.get_pref("color", Color(0, 0, 0, 0))
    PlayerPrefs.get_pref("item_rect", Rect2(0, 0, 0, 0))

# Load complete information

func get_player_base():
    PlayerPrefs.get_base()

Check Data

Use Editor option to check saved preferences. README Alt text

It will print the data in the console.

Save player preferences in-game similar to other game engines. This is a simple class that allows you to save and load data in a file. It is very easy to use and it is very useful for saving game data.

** New **

- Add an editor option to check saved Preferences.
- Add pref change/set signal.

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
PlayerPrefs icon image
Kshitij
PlayerPrefs

Save player preferences in-game similar to other game engines. This is a simple class that allows you to save and load data in a file. It is very easy to use and it is very useful for saving game data.** New **- Add an editor option to check saved Preferences.- Add pref change/set signal.

Supported Engine Version
4.1
Version String
0.2
License Version
MIT
Support Level
community
Modified Date
1 year ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers