sorry to bring up an old thread, but i seem to have some issues with [System.Serialisable] when using it on a class in a different file i no longer can see the class in the inspector, anyone know whats up with that?
Is the file in a different namespace or even different project? Usually files in the normal project cannot see files included in the Editor project. Can you tell us some more info about your classes?
I notice you wrote that â[System.Serialisable]â, but it should be â[System.Serializable]â, so if you typed it that first way, that would be why youâre not seeing it.
found the answer, when you create a new calss in unity it automatically derives from MonoBehaviour⊠remove that and add [System.Serializable] and you will be set
MonoBehaviour is already serializeable, so you donât need to add it to a class that inherits from from it.
But itâs perfectly fine and recommended to remove the MonoBehavior inheritence if you do not need to make any use of monobehavior stuff like Update(), Start(), and many other runtime features it provides.
It doesnât matter what namespace theyâre in, if the class has a reference defined in some Monobehaviour based script that is being displayed in the inspector, then all that matters is that the class definition has [System.Serializable] above it, and that you put [SerializeField] beside the reference you want to indicate should be shown in detail in the inspector.
so the problem was that I defined my reference with { get; set;} at the end so it wouldnât show in the editor. is there any way around it? keeping { get; set;} format?
Properties are basically methods, they donât hold references to anything. What happens when you define an auto-property like that is that an actual reference variable is created at compile time that your Property âgetsâ and âsetsâ to.
What you should be doing is:
[SerializeField] private SomeClass myClassRef;
public SomeClass MyClassProp
{
get {return myClassRef;}
set{ myClassRef = value;}
}
This is how youâre supposed to use a Property. Otherwise there isnât much point in making a property, things can always be refactored later if you need Property functionality (i.e to make certain things happen if you set or get a field).
Honestly this C# seems a big stepback. Iâm fed up to search for things that used to wok in Unityscript and are now broken.
We have computers that can recognize your face in a fraction of a second, but you still have to type 1.0f to make a compiler understand youâre dealing with a floating point number, or type â;â to finish a line, or more intricate things like the above. Also documentation in some areas is lacking. By the way, thanks for the help here, which would not be needed if Unity did proper documentation.
This is not about democratization anymore, but nerds and shamans ruling.
Unityscript was used about 14.6% globally(actually itâs way less than that, as 14.6% was the percentage of projects that contained at least one js file which can also be attributed to StandardAssets, not the percentage of projects exclusively in unityscript which was about 0.8%). Does it make sense to continue supporting this backend and allocate resources for it? It didnât make sense to have multiple backends anyway. The fact that Boo made it as far as it did is surprising enough.
The docs themselves do cover the issue at hand. Unity - Manual: Script serialization and also following some of the links from this page you discover Unity - Scripting API: Serializable
Not to mention all the sticky threads and Unite videos featuring Tim Cooper talking about serialization.