Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Problem with JSONSerializeModule

Discussion in 'Scripting' started by sodabuz, Mar 3, 2019.

  1. sodabuz

    sodabuz

    Joined:
    Jan 9, 2019
    Posts:
    1
    Hi,

    I keep getting the: "The type or namespace name 'JSONSerializeModule' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)" error at line 5

    But the documentation is clear: https://docs.unity3d.com/ScriptReference/UnityEngine.JSONSerializeModule.html

    Any help will be appreciated. Thx



    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.JSONSerializeModule;

    public class OdooAuthenticate : MonoBehaviour
    {

    [Serializable]
    public class OdooAuthInfo
    {
    public string db;
    public string user;
    public string password;
    }

    void Start()
    {
    OdooAuthInfo odooAuthInfo = new OdooAuthInfo();
    odooAuthInfo.db = "odoo_unity";
    odooAuthInfo.user = "admin";
    odooAuthInfo.password = "admin";

    string json = JsonUtility.ToJson(odooAuthInfo);
    Debug.Log(json);
    }
    }
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Prior to 2018.3, it was in the root UnityEngine namespace. Are you on an older version?

    Alternatively, do you have the correct package/assembly imported in the newer version's package manager?
     
  3. KiryaRizhiy

    KiryaRizhiy

    Joined:
    Apr 13, 2019
    Posts:
    3
    Had same problem. Updated Unity to 2019.1.0f2. Now JsonUtility class is compiling norm without using JSONSerializeModule.
     
    rosco_y likes this.
  4. rosco_y

    rosco_y

    Joined:
    Aug 3, 2016
    Posts:
    31
    Having the same problem, and I tried finding JSONSerializeModule in the Package Manager with no luck.

    I'm using Unity 2020.3.15f2
     
  5. rosco_y

    rosco_y

    Joined:
    Aug 3, 2016
    Posts:
    31
    Thank you, I deleted the "using UnityEngine.JSONSerializeModule" and just started using the JsonUtilty class--works fine--I guess the docs need to be updated.
     
  6. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,524
    I think people need to learn the difference between a module / assembly and a namespace. The JsonUtility class has always been in the UnityEngine namespace since it was created. Unity just has split up their engine code into seperate modules. The documentation of the JsonUtility class clearly states that it's in the namespace "UnityEngine". Again, assemblies and namespaces are two different things. While it is common to place classes that are defined in a seperate assembly inside a namespace that has the same / a similar name as the assembly, it's not necessary at all. Even the .NET framework has many assemblies that define classes in various namespaces.

    You can find the UnityEngine.JSONSerializeModule in the package manager when you switch to "Built-in" packages at the top. Though the built-in packages should be included by default anyways.