VeriorPies / ParrelSync

(Unity3D) Test multiplayer without building
MIT License
4.67k stars 322 forks source link

[BUG] PlayerPrefs keep the same values between editor instances #46

Closed pawelsalwa closed 3 years ago

pawelsalwa commented 3 years ago

Describe the bug If we change PlayerPrefs value inside any editor (clone or original) all other editors have their changes reflected.

To Reproduce Steps to reproduce the behavior:

  1. Set any PlayerPref value in any editor instance.
  2. Read the data on any other editor instance.

Expected behavior Expected - PlayerPrefs value changes are only local to each editor

314pies commented 3 years ago

Hi pawelsalwa , PlayerPrefs is an API provided by Unity, and it's probably not a good idea to change its behavior. Although we can make some kind of wrapper to it, as this will affect the final build code and increase project dependency with ParrelSync, it's still more prefer to leave it to the developer themselves to decide.

314pies commented 3 years ago

There's a IsClone API to know whether the current editor is clone or not. You may consider do something like this if you want to have separated PlayerPrefs value for the clone.

string key = "playerPrefsKey";

#if UNITY_EDITOR
if (ClonesManager.IsClone()) { key += "_clone";}
#endif

int pValue= PlayerPrefs.GetInt(key , 0);