Freezes in Play Mode when selecting an object that has had JsonUtility.FromJsonOverwrite() run

I’ve found some peculiar behaviour in Unity 6. I have a GameObject with a MonoBehaviour script that calls a ‘load’ function OnEnable():

public class Profile : MonoBehaviour {
  void OnEnable(){
          JsonUtility.FromJsonOverwrite(PlayerPrefs.GetString(key), this);
  }
}

When in play mode and then clicking on the object in the Hierarchy window it causes Unity to freeze. As far as I can tell there are no errors, nothing output on the logs, nothing. Bug reporter doesn’t show, just freezes.

This has been in my code for 5+ years, but on the update to Unity 6 this has caused issues. If I don’t click on the GameObject with the script on I have no issues, data gets overwritten and everything works as expected. However as this is a save data object, being able to see the data in the Inspector helps greatly with debugging!

Has anyone found this issue, or have a work around?

1 Like