Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by nickyoso1 · Dec 23, 2016 at 01:57 PM · inspectorlists

Unity Inspector limiting display of nested lists.

I'm having a problem where when I want to inspect an object that has nested lists in the inspector causes the unity editor to become unresponsive.

I basically have the following code:

 [System.Serializable]
 public class Cell{
      public List<Cell> AdjacentCells;
 }

And a monobehaviour that has a Cell[].

In my current testscene I have 4 Cells and each of the cell has the three other ones as an adjacent cell, so: cell 1 has cell 2, 3 and 4 as adjacent cells. cell 2 has cell 1, 3 and 4 as adjacent cells. etc.

the problem is when I want to inspect that monobehaviour to make sure all adjacentcells are properly set, unity becomes unresponsive because when it want to display the properties it is basically doing an endless loop through those lists of adjacent cells.

Now I was wondering if anyone knows of a way to make a custom inspector that only shows the adjacent cells for the root nodes?

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
0
Best Answer

Answer by Adam-Mechtley · Dec 23, 2016 at 02:19 PM

The problem is that this can exceed the serialization depth limit. Your cell has a list of cells, each of those has a list of cells, and so on potentially infinitely.

Please see my answer on this question for a possible solution.

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 nickyoso1 · Dec 23, 2016 at 02:34 PM 0
Share

If i understand correctly, you are suggesting to replace the List adjacentcells with a List containing the indices of the cells?

avatar image Adam-Mechtley nickyoso1 · Dec 23, 2016 at 03:07 PM 0
Share

Something like that would work, yes

avatar image
0

Answer by Bunny83 · Dec 23, 2016 at 02:32 PM

This kind of structure is not supported by Unity's serialization system, It's not really a visual / display problem. Custom serializable classes are not serialized as unique instance but simply has sub and sub-sub properties of the MonoBehaviour instance. Circular dependencies are not supported at all. The serializer usually detects such things since it simply stops after a nested depth of 7.

You need your cells as an actual asset which can be referenced. So either make it a MonoBehaviour or a ScriptableObject. Those can be serialized on their own and have an actual asset / instance ID which is used for cross references between assets / instances.

An alternative way is to only have a single array with all cells in it, make the List non serialized and use the ISerializationCallbackReceiver interface to save the cross references in a different way. For example as indices into that large array. Though it's usually better to use ScriptableObjects and save them as assets. Keep in mind that you can save multiple ScriptableObjects into a single assetfile. Just have a look at the AssetDatabase and more specifically AddObjectToAsset.

Of course displaying them in a tree-like fashion requires you to create a custom inspector for your MonoBehaviour,

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 nickyoso1 · Dec 23, 2016 at 02:55 PM 0
Share

ScriptableObjects unfortunately won't work for me, as I generate the cells at runtime. I could turn it into a $$anonymous$$onoBehaviour and that will also give me some other benefits unrelated to this problem. The only thing I worry about is the performance impact: I could see use-cases where I would have 10,000 cells, I don't know what kind of performance impact those 10,000 monobehaviours would have.

avatar image Bunny83 nickyoso1 · Dec 23, 2016 at 03:32 PM 0
Share

Huh? You can create ScriptableObject at runtime just like you can create $$anonymous$$onoBehaviours at runtime ^^. The inspector is mainly ment for displaying serialized data at edit time. If you just care about displaying the classes at runtime, you can simply make your List "NonSerialized" so Unity's serialization system doesn't mess with the list.

Now you can implement a custom inspector that directly reads the instances from the "target" instance and displays the GUI you like. However you have to explicitly display the GUI for each variable manually as you can't use SerializedObject / SerializedProperty for this. So this wouldn't be a generic solution but a specific custom solution for your "Cell" class. If you have trouble getting started with I$$anonymous$$GUI, have a look at my GUI crash course ^^. Currently (at least what you showed us) your Cell class is essentially empty so we can't tell how difficult the GUI might get.

edit
I had once such a case where i didn't create a custom inspector but a quick and dirty EditorWindow to display the structure of my neural network. It was a pure "viewer" to inspect the current weights of each connection.

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

63 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Two lists with related sizes 1 Answer

Modifying Lists via the inspector 1 Answer

Serialization of list in list problem with depth 0 Answers

How do I retrieve an item from a list? 1 Answer

pre populate nullable type list items in inspector 0 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