Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Unity 2018.1b12 - MenuItem errors out if submenu of "Component"

Discussion in '2018.1 Beta' started by Aurelinator, Mar 29, 2018.

  1. Aurelinator

    Aurelinator

    Joined:
    Feb 27, 2012
    Posts:
    19
    Hi all,

    I've been noticing some errors after upgrading our project to 2018.1b12 from b11. It looks like Unity has added some enforcing of the Component submenus, where validate functions are now necessary. The problem is that many of the external plugins we have, are written without validate functions for their menus, and if those menus were placed in the Component submenu, then this causes errors.

    Here's a simple repro:

    1. Create a new project.
    2. Create this script.

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. public static class Potato
    5. {
    6.     [MenuItem("Component/Potato")]
    7.     public static void Potate()
    8.     {
    9.         Debug.Log("Potato");
    10.     }
    11. }
    12.  
    Compile and access the component menu, and you'll see the error in the console after clicking it.

    upload_2018-3-29_13-56-32.png

    Ok, you may say - that's not a big deal - update that yourself and add a validation component or use the `AddComponentMenu` attribute. Well, the problem is when it comes not from my own code, but from third party assets that are using say
    [MenuComponent("Component/ThirdPartyAsset")]
    .

    Some examples, from, say the Obi rope plugin we're using:

    upload_2018-3-29_14-1-51.png

    Now in this case, I have access to the code because I have the source code and can tweak it. But other things are using DLLs that have those menu items hardcoded and I can't change those.

    Additionally, I don't know when or why this is happening, but at random times, the error messages will just pop up randomly, even in gameplay, which sucks if you have Error-Pause turned on to diagnose all errors.

    Anyway - I'm not sure if this is a regression or not - it looks pretty clear that things coming from the Component Menu need a validate function now, and without it won't exactly work, but the error that's coming out is a bit annoying and I can't do anything if it comes from compiled DLLs.

    It happens sometimes when I boot unity and then at random other times, even though I'm not using the Component menu or even using those features at all.

    upload_2018-3-29_14-9-8.png
     
  2. Aurelinator

    Aurelinator

    Joined:
    Feb 27, 2012
    Posts:
    19
    The problem still persists in b13. This is clearly a regression or a change from b11 to b12. Is this intentional? The error is very annoying and sucks when I'm using precompiled external plugins that have those paths hardcoded and can't actually change it.

    It happens at random times - so I'm not sure what's actually triggering it. I've even tried adding "Validation" functions for the methods that I have access to but it looks like the issue is still persisting. Short of changing the code to not be in the Component submenu, is there something that can be done here?
     
  3. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,659
    What's the bug number?