Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
avatar image
1
Question by Golan2781 · Dec 28, 2012 at 10:53 PM · javascriptinspectorstruct

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;
 }


Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
-1
Best Answer

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

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 Golan2781 · Dec 29, 2012 at 08:25 AM 0
Share

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.

avatar image
20

Answer by jannis99 · Dec 11, 2015 at 03:23 PM

Serializing structs in Unity is actually possible now. I found this on the forums (Link):

     [System.Serializable]
     public struct PlayerStats
     {
         public int moveSpeed;
     }

I have tried it and it works fine.

Comment
Add comment · Show 2 · 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 Zeratul3D · Jul 26, 2018 at 04:02 PM 1
Share

Works perfectly also on Unity 2018.

avatar image Zack-Londres · Aug 04, 2020 at 06:41 PM 1
Share

This is the way

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

13 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

Related Questions

Multiple classes inside each other 1 Answer

Help with a custom inspector field. 0 Answers

Need health to decrease with movement in Javascript 1 Answer

Inspector Assigned Variables Not In Both Scenes 1 Answer

Having Variables store a script in the inspector 2 Answers


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