Search Issue Tracker
Won't Fix
Votes
1
Found in
2021.3.30f1
2022.3.9f1
2023.1.12f1
2023.2.0b8
2023.3.0a4
Issue ID
UUM-48261
Regression
No
"PlayerPrefs.GetString" returns an empty string when the default value is set to "null"
Reproduction steps:
1. Open project “PlayerPrefsRepro.zip”
2. Open “SampleScene”
3. Enter Play Mode
4. Observe the Console
Expected result: No error is thrown
Actual result: “AssertionException: Assertion failure. Values are not equal. Expected: == “ error is thrown in the console
Reproducible with: 2021.3.30f1, 2022.3.9f1, 2023.1.12f1, 2023.2.0b8, 2023.3.0a4
Reproducible on: macOS Ventura 13.2.1 (Intel), Windows 11 (by the reporter)
Not reproducible on: no other environment tested
Notes:
- Also reproducible in Standalone Player
- changing line 12 in “Repro.cs” to {{Assert.AreEqual("", PlayerPrefs.GetString("test-key", null));}} gives Expected results
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Unity CIL Linker fails on Player build when persistent listeners have "<" and ">" in their XML attribute names
- ”Lighting data asset ‘LightingData’ is incompatible with the current Unity version…” warnings are thrown when saving Indoors (URP) and Outdoors (URP) Scenes as Scene Templates
- [iOS] The screen blinks when transitioning from custom to Unity splash screen
- [macOS] ”Ignoring depth surface load action as it is memoryless” warnings are thrown when taking Game View Snapshot
- UI Builder Inspector scrolls back up when changes on an expanded but not fully displayed Inspector tab are saved
Resolution Note:
This is by design. You can never get null from PlayerPrefs.GetString() API.