Search Unity

CreateAssetMenu not appearing in Create-menu

Discussion in 'Scripting' started by Pixygon, Jan 13, 2018.

  1. Pixygon

    Pixygon

    Joined:
    May 9, 2013
    Posts:
    26
    I've made several ScriptableObjects, where instances can be created using the Create submenu in the project. This has worked fine the last three months, but now I don't get the menu option at all, for any of my scriptable objects. I've tried deleting and re-downloading the project, edit the scripts to see if it appears again, changing the name of the object in the create menu, but with no luck.
    Is there anyone that have an idea about what could have happened?
     
  2. ExplosiveBarrels

    ExplosiveBarrels

    Joined:
    Oct 18, 2016
    Posts:
    11
    This bug is happening to me now too.
    Did you ever find a solution?

    EDIT: Actually, nevermind, I solved my particular case. I had switched most of my ScriptableObjects to inherit from the same base class, but that base class was accidentally a MonoBehaviour instead of ScriptableObject, so one quick fix there re-enabled them all.
     
    Last edited: Aug 12, 2018
  3. combinesoldat

    combinesoldat

    Joined:
    Apr 2, 2019
    Posts:
    1
    Changing the class from MonoBehavior to ScriptableObject solved it for me.
     
  4. Daxawn

    Daxawn

    Joined:
    Dec 6, 2019
    Posts:
    8
    I was trying to use a scriptable object but when i create it doesn't appear in unity, its such a strang thing. Some idea how to solve it?
    e4ecbd601d4d74304cb3a3f40fd42823.png
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [CreateAssetMenu(fileName = "DungeonGenerationData.asset", menuName = "DungeonGenerationData/Dungeon Data")]
    4. public class DungeonGeneratorData : ScriptableObject {
    5.     public int numberOfCrawlers;
    6.     public int iterationMin;
    7.     public int iterationMax;
    8. }
    9.  
     
  5. Remjie

    Remjie

    Joined:
    Dec 15, 2016
    Posts:
    1
    Hi bros,
    @Daxawn : Have you tryed to dont use extention on filename && maybe try to doesnt use space character on name?

    Code (CSharp):
    1.  using UnityEngine;
    2.    
    3. [CreateAssetMenu(fileName = "DungeonGenerationData", menuName = "DungeonGenerationData/Dungeon_Data")]
    4. public class DungeonGeneratorData : ScriptableObject {
    5.         public int numberOfCrawlers;
    6.         public int iterationMin;
    7.         public int iterationMax;
    8. }
     
  6. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313
    In the arguments for CreateAssetMenu, fileName is the default name that the newly created instance of the SO should have, not how your file is called that contains the SO definition, such as:
    [CreateAssetMenu(fileName = "NewDungeonGenerationData", menuName = "Dungeon Generation/Dungeon Data")]
     
    yunzhencai and nafraus like this.
  7. Daxawn

    Daxawn

    Joined:
    Dec 6, 2019
    Posts:
    8
    I tryed to change it but it still doesnt appear the option.
    I was thinking that it could be the version, I mean, Im using the 2018.4.13f1 insteed of the new ones. Could it be the problem?
    Edit; nope it isnt, im using now the latest version and it still doesnt work. need help
     
    Last edited: Mar 13, 2020
  8. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313
    Make sure that your file has the same name as your ScriptableObject definiton. Your project may also not have any other errors [in the console], since they stop Unity from refreshing its menu or something like that.

    As for the arguments for the attribute, try using the parameterless attribute first, being
    [CreateAssetMenu]
    . Does this show up? It might not show up at the top, but at the very bottom. In the past, experienced some odd behaviors around that, appearently being dependent on your operating system.
     
  9. Daxawn

    Daxawn

    Joined:
    Dec 6, 2019
    Posts:
    8
    I do have two errors on my console but i thnik those are because i havent created the assetmenu yet. I'll insert u n image.


    I also tryed to rename the file and then the name in the code
    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3.  
    4. [CreateAssetMenu(fileName = "NewDungeonGenerationData", menuName = "DungeonGeneration/DungeonData")]
    5. public class NewDungeonGeneratorData : ScriptableObject {
    6.     public int numberOfCrawlers;
    7.     public int iterationMin;
    8.     public int iterationMax;
    9. }
    If cant find solution we can contact by email and ill send u some videos, so it will be easier, if u want of course
     
  10. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313
    Those error messages have to be fixed, because they are related to your problem. Basically, Unity detects that something is wrong, here not finding a type named "NewDungenGenerationData" which you use in DungeonCrawlerController and DungeonGenerator and thus the editor is not "refreshed", not displaying the data in your list of creating new objects.

    Try this one:
    Code (CSharp):
    1.     using System;
    2.     using UnityEngine;
    3.  
    4.     [CreateAssetMenu(fileName = "NewDungeonGenerationData", menuName = "DungeonGeneration/DungeonData")]
    5.     public class DungeonGeneratorData : ScriptableObject {
    6.         public int numberOfCrawlers;
    7.         public int iterationMin;
    8.         public int iterationMax;
    9.     }
    10.  
    Make sure that in DungeonCrawlerController and DungeonGenerator, you use "DungeonGeneratData" accordingly and not "NewDungeonGenerationData".

    Again,
    fileName = "NewDungeonGenerationData"
    is not the file name of your script containing the defnition of your ScriptableObject. It is the name that new instances of your ScriptableObject have as default name.
     
  11. Daxawn

    Daxawn

    Joined:
    Dec 6, 2019
    Posts:
    8
    Yeah thats the problem. I have been using always DungeonGenerationData and it neither works.

    Moreover that errors i think that appear because the scriptable object is missing but i cant create it, so im in a loop.
     
  12. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313
    I think you confuse ScriptableObject definition and ScriptableObject instance. The code that you write in your file, that is your SO definition. Once you create an asset using the asset menu based on your definiton, those are your SO instances.

    Look at your error messages. They come from
    DungeonCrawlerController.cs
    and
    DungeonGenerator.cs
    . These errors prevent you from creating new SO instances, because Unity does not refresh the corresponding menu where the option should appear until your project is error free.

    It is hard to tell without the actual files, however, you can open the files in your integrated development environment and it shows you the line and usually marks the error. Just guessing, renaming your SO definition, you did not refactor your code but directly renamed it. In other words, wheresoever you still use the old name of your SO definition, you get an error because the type does not exist anymore since you renamed it.

    I tested the SO defintion that I showed in my earlier post and it allows you you to create instances from it using the asset menu.
     
    Bunny83 likes this.
  13. Daxawn

    Daxawn

    Joined:
    Dec 6, 2019
    Posts:
    8
    Ok I managed to go on a bit. I managed to create the instance from the asset menu by commenting every line that gave me error but when i create the object it doesn't detect any script. Look:

     
  14. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313
    Try deleting the SO instance and create a new one. Unity might still be confused. When refactoring your code, such as making name changes, it is a good idea to give Unity a moment until it got everything in order.
     
  15. Daxawn

    Daxawn

    Joined:
    Dec 6, 2019
    Posts:
    8
    Yeah i have already tryed multiple times but it doens't give any script.
    On the other hand the errors are still there n I dont know how to solve them. I think that has been the problem always and not until i solve it anything will work.
    Could you tell me any way to solve it?
     
    Last edited: Mar 22, 2020
  16. Brokencutlass

    Brokencutlass

    Joined:
    Mar 18, 2019
    Posts:
    110
    Just have to jump on this and add I am having the same issue. Have worked for weeks. Made a new code using the same asset menu (copied and pasted it even) and now the entire thing is gone and will not appear no matter what I do.
     
  17. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313
    Do you mean that you have two or more SO definitions that have the same
    menuName
    path in the class attribute? That won't work, you have to give every SO definition with the
    [CreateAssetMenu]
    an unique
    menuName
    argument. If they are the same path, Unity most likely doesn't decide which one to display and doesn't display it at all.
     
  18. Brokencutlass

    Brokencutlass

    Joined:
    Mar 18, 2019
    Posts:
    110
    Actually, sorry for being off for awhile, I figured it out. It was something so simple lol
     
  19. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313
    Please share the reason and solution so people who have the same problem can check if it is the same reason for them.
     
    rogodoy likes this.
  20. SafaMagdy

    SafaMagdy

    Joined:
    May 15, 2021
    Posts:
    1
    I tried replacing the word "filename" with "fileName" and it worked.
     
  21. TheHeroSight

    TheHeroSight

    Joined:
    Jul 4, 2020
    Posts:
    1
    Hi I'm have experienced the same issue and I couldn't find a way to fix it.
    this is my code if anyone could help me.


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;


    namespace LP.FDG.Player.Units
    {
    [CreateAssetMenue(fileName = "New Unit", menuName ="New Unit")]

    public class Unit : ScriptableObject
    {
    public enum unitType
    {
    Builder,
    Soilder,
    Tank,
    Helicopter,
    Supplies,
    Jett,
    };
    public bool isPlayerUnit;

    public unitType type;

    public new string name;

    public GameObject unitPrefab;

    public int coast;
    public int attack;
    public int health;
    public int armor;
    public int explosive;
    public int expHealth;
    }

    }
     
  22. Shadowfight2

    Shadowfight2

    Joined:
    Apr 8, 2022
    Posts:
    2
    Hello also having a problem with the script menu. I believe the CreateAssetMenu is to change it color
     

    Attached Files:

  23. Shadowfight2

    Shadowfight2

    Joined:
    Apr 8, 2022
    Posts:
    2
    I think I found the solution your script editor should be on VS not open file by extension
     

    Attached Files:

  24. WigglingPotatoDev

    WigglingPotatoDev

    Joined:
    Sep 13, 2017
    Posts:
    3
    I encountered the same problem. My SO didn't show up in the (Assets) create menu. I recall renaming either the class name or filename of the .cs script file because I was still deciding what to call them. The menu still didn't show up even though I made the two names the same. I think something in the support files was corrupt.

    I ended up creating a new file, and not messing with the classname or .cs filename of the script afterwards.
     
  25. outside_visitor

    outside_visitor

    Joined:
    Oct 22, 2021
    Posts:
    1
    I can't find CreateAssetMenu in Unity documentation – only CreateAssetMenuAttribute (and both are working for me). What's the difference?

    My SO is showing up in the Create menu now that I'm inheriting from ScriptableObject, but I'm following a tutorial in which the SO gets to be shown in the Create menu even when inheriting from a custom class. Why so?
     
  26. henryfjones

    henryfjones

    Joined:
    Feb 29, 2020
    Posts:
    4
    I've run into this issue today too. I already had a scriptable object that I could create from the asset menu so I couldn't understand why I couldn't create a new one. I believe the cause of my issue was the length of the file path to the script. My Unity project is nested deep within other organisational folders and it seems the long menuName + fileName went beyond whatever limit the file path is on Windows.

    I shortened the name of the menuName in the CreateAssetMenu and it's now showing up.

    I hope this may help someone else with the same issue.
     
  27. Delphoenyx

    Delphoenyx

    Joined:
    Jun 20, 2021
    Posts:
    4
    I had the same issue explained at the beggining. In my case, I had to fix some console errors and it worked just fine after that.
    I don't know how related to the script my errors were, but the errors were NOT about my scriptable object.
     
    flat07 likes this.
  28. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,856
    Generally you need fix all compiler errors for Unity to recompile properly and for attributes like CreateAssetMenu and MenuItem to work properly, regardless if the class in question is the cause of the errors.
     
    Kerphelio and Bunny83 like this.
  29. howard_76

    howard_76

    Joined:
    Aug 30, 2022
    Posts:
    1
    I am in some desperate need of help, I was trying to use a scriptable object and it will not let me, anyone got any ideas, previous post ideas did not help fix this for some reason.
    upload_2022-8-30_23-32-24.png
     

    Attached Files:

  30. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    497
    You're not using a ScriptableObject, your class is a normal MonoBehaviour. If you want it to be a ScriptableObject then that is what your class should be.
     
    Bunny83 likes this.
  31. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    So take a deep breath and please stop necro-posting.

    If you have an issue, please start your own post... it's FREE!

    When you post, remember, photographs of code ARE NOT A THING.

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    This is the bare minimum of information to report:

    - what you want
    - what you tried
    - what you expected to happen
    - what actually happened, especially any errors you see
    - links to documentation you used to cross-check your work (CRITICAL!!!)

    REMEMBER: it is up to you to do the necessary TWO STEPS to do tutorials / example code:

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    Fortunately this is the easiest part to get right: Be a robot. Don't make any mistakes.
    BE PERFECT IN EVERYTHING YOU DO HERE!!

    If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!
     
    Bunny83 likes this.