Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by LokoGame · Aug 08, 2017 at 08:40 AM · jsonsave datasaveloadformatsave-to-file

Cannot deserialize JSON to new instances of type 'X'

I'm making a menu of options, and I want the settings made to be saved in .json format, that does not give any errors, but when I start the game and I want to load them, it says:

Can not deserialize JSON to new instances of type 'X'

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using System.IO;
 
 public class SettingManager : MonoBehaviour {
     public Toggle fullscreenToggle;
     public Dropdown resolutionDropdown;
     public Dropdown textureQualityDropdown;
     public Dropdown antialiasingDropdown;
     public Dropdown vSyncDropdown;
     public Slider musicVolumeSlider;
     public Button applyButton;
 
     public AudioSource musicSource;
     public Resolution[] resolutions;
     public GameSettings gameSettings;
 
     void OnEnable()
     {
         gameSettings = new GameSettings();
 
         fullscreenToggle.onValueChanged.AddListener(delegate { OnFullscreenToggle(); });
         resolutionDropdown.onValueChanged.AddListener(delegate { OnResolutionChange(); });
         textureQualityDropdown.onValueChanged.AddListener(delegate { OnTextureQualityChange(); });
         antialiasingDropdown.onValueChanged.AddListener(delegate { OnAntialiaingChange(); });
         vSyncDropdown.onValueChanged.AddListener(delegate { OnVSyncChange(); });
         musicVolumeSlider.onValueChanged.AddListener(delegate { OnMusicVolumeChange(); });
         applyButton.onClick.AddListener (delegate { OnApplyButtonClick(); });
 
         resolutions = Screen.resolutions;
         foreach(Resolution resolution in resolutions)
         {
             resolutionDropdown.options.Add(new Dropdown.OptionData(resolution.ToString()));
         }
             
         if (File.Exists(Application.persistentDataPath + "/gamesettings.json") == true)
         {
             LoadSettings();
         }
     }
 
     public void OnFullscreenToggle()
     {
         gameSettings.fullscreen = Screen.fullScreen = fullscreenToggle.isOn;
     }
 
     public void OnResolutionChange()
     {
         Screen.SetResolution(resolutions[resolutionDropdown.value].width, resolutions[resolutionDropdown.value].height, Screen.fullScreen);
     }
 
     public void OnTextureQualityChange()
     {
         QualitySettings.masterTextureLimit = gameSettings.textureQuality = textureQualityDropdown.value;
     }
 
     public void OnAntialiaingChange()
     {
         QualitySettings.antiAliasing = gameSettings.antialiasing = (int)Mathf.Pow(2f, antialiasingDropdown.value);
     }
 
     public void OnVSyncChange()
     {
         QualitySettings.vSyncCount = gameSettings.vSync = vSyncDropdown.value;
     }
 
     public void OnMusicVolumeChange()
     {
         musicSource.volume = gameSettings.musicVolume = musicVolumeSlider.value;
     }
 
     public void OnApplyButtonClick()
     {
         SaveSettings();
     }
 
     public void SaveSettings()
     {
         string jsonData = JsonUtility.ToJson(gameSettings, true);
         File.WriteAllText(Application.persistentDataPath + "/gamesettings.json", jsonData);
     }
 
     public void LoadSettings()
     {
         gameSettings = JsonUtility.FromJson<GameSettings>(File.ReadAllText(Application.persistentDataPath + "/gamesettings.json"));
 
         musicVolumeSlider.value = gameSettings.musicVolume;
         antialiasingDropdown.value = gameSettings.antialiasing;
         vSyncDropdown.value = gameSettings.vSync;
         textureQualityDropdown.value = gameSettings.textureQuality;
         resolutionDropdown.value = gameSettings.resolutionIndex;
         fullscreenToggle.isOn = gameSettings.fullscreen;
     }
 }
 
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image LokoGame · Aug 08, 2017 at 11:55 AM 0
Share

@haruna9x |This script I've taken from the internet, and I do not understand what I should do, I've tried it but it gives me errors. Can you explain it a little better?

Sorry for my bad English, I'm from Spain.

avatar image LokoGame LokoGame · Aug 08, 2017 at 01:37 PM 0
Share

@haruna9x | I'm really sorry if I bother you too much, but it's that you can not delay any more, it's the last thing that is loaded in the game, and I do not know I have to overwrite.

avatar image LokoGame · Aug 08, 2017 at 01:36 PM 0
Share

@haruna9x | I'm sorry if I bother you too much, but it's that you can not delay any more, it's the last thing that is loaded in the game, and I do not know I have to overwrite :(

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Unplug · Jan 24, 2018 at 01:49 PM

I came across the same problem. You simply forgot to delete the monobehavior from gamesettings. open the file and make sure it read

 public class GameSettings {
 

you probably have the standard ending " : Monobehavior { " but JSON cannot read monobehavior class and this is what it is trying to tell you. they only read class.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DryreL · Jun 20, 2021 at 10:54 AM 0
Share

This time I'm getting following errors: alt text

image-2021-06-20-125415.png (51.8 kB)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

115 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[Error:] Cannot Deserialize JSON to new instances of type ' X ' 1 Answer

Serialize gameobject children behaviours 0 Answers

Save location of created UI elements to JSON so it can load later 0 Answers

How To Save and Load player position using Serialization? 0 Answers

jsonUtlility save/load ScriptableObjects 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges