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 Mr-Q928 · Apr 13, 2017 at 09:54 AM · editorevent

UnityEvent Editor breaking in nested struct

We are using UnityEvent for our in-game menu but we ran into some issues when trying to use it in a nested struct for sub menus. It works fine in the top level struct but breaks in the sub level structs.

 public class TestScript : MonoBehaviour
 {
     [Serializable]
     public struct menuItem
     {
         public UnityEvent menuEvent;
         public menuItem[] subMenu;
     }
     public menuItem[] menuItems;
 }

It throws the following error

type is not a enum value UnityEditor.SerializedProperty:get_enumValueIndex() UnityEditorInternal.UnityEventDrawer:GetMode(SerializedProperty) (at C:/buildslave/unity/build/Editor/Mono/Inspector/UnityEventDrawer.cs:161) UnityEditorInternal.UnityEventDrawer:DrawEventListener(Rect, Int32, Boolean, Boolean) (at C:/buildslave/unity/build/Editor/Mono/Inspector/UnityEventDrawer.cs:196) UnityEditorInternal.ReorderableList:DoListElements(Rect) (at C:/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:576) UnityEditorInternal.ReorderableList:DoList(Rect) (at C:/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:401) UnityEditorInternal.UnityEventDrawer:OnGUI(Rect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/UnityEventDrawer.cs:146) UnityEditorInternal.UnityEventDrawer:OnGUI(Rect, SerializedProperty, GUIContent) (at C:/buildslave/unity/build/Editor/Mono/Inspector/UnityEventDrawer.cs:115) UnityEditor.DockArea:OnGUI() Picture of Inspector

Is this a known issue and if so does anyone know how to fix this or know of a work around?

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

1 Reply

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

Answer by Bunny83 · Apr 13, 2017 at 10:14 AM

First of all i wouldn't recomment using a struct here. Even Unity now supports structs it usually gives you more headache than it does any good.

Next thing is, unfortunately, you can't have a recursive structure, at all. "menuItem" has "menuItem"s as childs. The Unity serializer don't like this. The max overall serialization depth is only about 7 i think. However recursive structures will trigger a safety switch which doesn't allow such structures at all even when the depth isn't actually reached.

Finally the UnityEvent class already has several childs. The UnityEventBase class (the base of UnityEvent) has a "PersistentCallGroup" class as child. The PersistentCallGroup class has a List of "PersistentCall" classes. The PersistentCall has an "ArgumentCache" class as child. So a UnityEvent already has about 3 depth layers internally so yo uhave to be careful how deep you nest a UnityEvent.

In your particular case the problem most likely comes from the recursion. If you need a structure like that, you have to use ScriptableObjects which can be serialized on their own and can be cross referenced.

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Get mouse position in Editor based on screen coordinates 1 Answer

The type or namespace name 'EventSystems' does not exist in the namespace 'UnityEngine' 0 Answers

Mouse click in edit mode. ✱✺✸❁ 1 Answer

UnityEvent draws debug variables in the inspector 0 Answers

ShowObjectPicker ObjectSelectorClosed command is never issued 1 Answer


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