Search Unity

CreateAssetMenu not working

Discussion in 'Package Manager' started by eheine, Mar 28, 2019.

  1. eheine

    eheine

    Joined:
    Jun 9, 2015
    Posts:
    5
    My team is trying to build a package of shared code to use across multiple projects and that code is using the
    CreateAssetMenu attribute to create various ScriptableObjects. When we import that same code as a package, the menu items no longer appear.

    Looking at how TextMeshPro gets its menu items to create assets, it has a separate editor file using the MenuItem attribute and manually creates the ScriptableObject asset. That seems really tedious since that's a lot of duplicate code we'd need to replace one line of existing code. Does the CreateAssetMenu attribute not working when bringing in code from the Package Manager?

    Thanks for the help!
     
  2. pablothedolphin

    pablothedolphin

    Joined:
    Oct 20, 2016
    Posts:
    94
    This should work since I've done the same thing at my own job. My ScriptableObject classes aren't in any editor folders or anything of the sort. Thought my set up is currently using local packages and not pointing to a scoped registry.
     
  3. pablothedolphin

    pablothedolphin

    Joined:
    Oct 20, 2016
    Posts:
    94
    Was working on my own code an remembered that you need a few things done first before your code can actually compile in your project. You need an assembly definition file at least at the root of your package code. This will tell Unity that everything at this folder level and bellow is part of its own assembly. This should force Unity to compile the package code if I'm not mistaken.

    If you want to refer to any of the classes you defined in your package in your main project code, you need to organise all your package code into namespaces and then add using statements for your new namespaces at the top of your project code.

    Outside of all that, I don't see any reason why the CreateAssetMenu attribute isn't working for you.
     
  4. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    574
    Hi @eheine,

    I spoke with the TextMeshPro package author. He said that he didn't try to use the
    CreateAssetMenuAttribute
    function. His implementation dates before the
    CreateAssetMenuttribute
    method existed. And a colleague tried to integrate the function in a package and it worked fine. He used this tutorial to test the feature: https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/scriptable-objects

    Can you follow the tutorial and see if you had missed something? If not, I suggest you file a bug report.

    Hope it will help!

    Pascal
     
  5. StephenHodgson-Valorem

    StephenHodgson-Valorem

    Joined:
    Mar 8, 2017
    Posts:
    148
    Not quite on topic but still a problem I've discovered with scriptable objects, is I have some extension methods that essentially make a copy of a scriptable object for users to then modify (via the gear in the top right of the inspector) but the whole inspector window is disabled and I cannot access that menu.
     
  6. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    574
    Hi @StephenHodgson-Valorem ,

    I'm just a regular user when it comes to areas other than the Package Manager. So I, and the other fellas monitoring this forum won't be super helpful with your specific issue. I suggest you expose your issue in the Editor & General Support forum. Or you can also fill a bug report. Especially if you have 100% repro!

    Regards,

    Pascal