- Home /
namespace error with [Serializable]
I receive this error with the code below:
"The type or namespace 'Serializable' could not be found (are you missing a using directive or an assembly reference?)
Any help would be greatly appreciated. I've been stuck for a couple hours.
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Collections.Generic;
public class Test_DataMgr : MonoBehaviour {
[Serializable]
public class TestClass
{
int TestInt;
}
}
Answer by mythraend · Sep 01, 2012 at 09:50 PM
Nevermind. After 4 hours of pulling hair I've found out you just put System.Serializable and it works.
In case this confuses anyone else - spent a while thinking this meant
using System.Serializable;
which barfs. Just put
using System;
you're the greatest
PS. Thanks Unity documentation (not!!) https://docs.unity3d.com/$$anonymous$$anual/JSONSerialization.html
should say using System; at the top of the example really
"4 hours of pulling hair" - You've saved me from going bald, thanks
Answer by GeneralV · Oct 07, 2013 at 12:40 AM
Alternatively, you can add the System
tag to the attribute itself. I.E.
public class Test_DataMgr : MonoBehaviour {
[System.Serializable]
public class TestClass
{
int TestInt;
}
}
Answer by Symbxlz · Jun 05, 2020 at 10:48 PM
More alternatively, add using System
so that you can just type [Serializable]
. I removed the using System
directive when I thought I didn't need it. Lesson learned, don't remove directives until you're done, so, probably never.
Your answer
Follow this Question
Related Questions
Unsupported type Generic Mono when using Serializable 2 Answers
How to serialize a gameobject using binaryformatter? 0 Answers
Can't run build-in script editor 0 Answers
Photon PUN offline mode didn't work 2 Answers
Unity Serializer scripting error 1 Answer