- Home /
custom struct not showing up in inspector?
I'm trying to cluster data into better handleable chunks. I'm experimenting with classes and Javascript structs (as described here). My custom structs are not showing up in the inspector even though similarly coded classes do! I can access/edit them from a script just fine but tracking them in the inspector or even setting their values is not possible. What's wrong wit my implementation?
#pragma strict
var dummy1 : Vector3; // shows up
var dummy2 : TestStruct; // does not show up
var dummy3 : TestClass; // shows up
var dummy4 : Vector3; // shows up
function Start () {
dummy2.t=2;
dummy3.t=3;
print(dummy2);
print(dummy2.t);
print(dummy3);
print(dummy3.t);
}
class TestStruct extends System.ValueType{
var x : float;
var y : float;
var z : float;
var t : float;
}
class TestClass {
var x : float;
var y : float;
var z : float;
var t : float;
}
Answer by Setzer22 · Dec 28, 2012 at 11:14 PM
I'm afraid this can't be done on Unity. Classes will do fine but structs can't be serialized with Unity and thus, won't display on the inspector. I don't know the reasons for this limitation (I think it's fair to call it a limitation) but I bet this is because of structs being value types, not refference ones, but as floats and integers can be assigned, there might be something else there...
Anyway, you might want to check this out: http://forum.unity3d.com/threads/36395-How-do-I-make-member-structs-accessible-in-the-editor?highlight=struct+inspector
Thanks, that'll save me a lot of time trying. :D
It seems like a pretty hefty limitation indeed, especially seeing how Unity's own structs work fine and fast. Is there a feature request for this? I wasn't able to find one.
Your answer
Follow this Question
Related Questions
How do I show a Classes Vars in the inspector (Javascript)?? 2 Answers
How does one declare a public variable without exposing it (in Javascript)? 0 Answers
Variables Won't Appear In Inspector 1 Answer
Javascript and C#, different behaviour in inspector ? 1 Answer
Why is my class hidden in inspector with C# and not JS? 1 Answer