Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

using [CreateAssetMenu()] and ScriptableObject

Discussion in 'Editor & General Support' started by Leqthor, Feb 17, 2018.

  1. Leqthor

    Leqthor

    Joined:
    Jan 30, 2018
    Posts:
    1
    Hello all. (and sorry if I've posted on the wrong thread)

    I'm new to unity, I tried looking on other threads and forums but nothing was helpful, I am watching a tutorial about procedural generation and I have a problem using the following code :

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

    [CreateAssetMenu()]
    public class TerrainData : ScriptableObject {
    // all my code
    }

    I am not able to find the Create TerrainData in the Create menu, it should've been added but it's not there, tried different approaches but neither did those solve anything. I'm using Unity 2017.3.1f1.

    I've tried to import the example project from the tutorial, it was from an older version but it worked, and it had the Create TerrainData and the others types of Create SomethingData on it, having the same script as I do ...
     
    duditonstudio likes this.
  2. Syganek

    Syganek

    Joined:
    Sep 11, 2013
    Posts:
    85
    First of all use Code tags when pasting code. Do not paste it directly to the editor.

    This script should work. It works for me. Check if your class name matches your script name.

    You should be able to access it using RMB in Project Window -> Create/Terrain Data or through top menu Assets/Create/Terrain Data. It should've be on the top of the list.

    You can also try to specify the path inside your [CreateAssetMenu()] attribute i.e.

    Code (CSharp):
    1. [CreateAssetMenu(menuName = "My Assets/Terrain Data")]
    2. public class TerrainData : ScriptableObject {}
     
  3. unity_HRrqzB0RoQgJOA

    unity_HRrqzB0RoQgJOA

    Joined:
    May 6, 2019
    Posts:
    1
    I have the exact same issue, don't know how to fix it though...
     
    parkjongwoo_nc and KarloE like this.
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,384
    Code (csharp):
    1. [CreateAssetMenu(fileName = "SUPER NEAT THING", menuName = "SUPER/NEAT/THING", order = 100)]
    2. public class SuperNeatThing : ScriptableObject
    3. {
    4.  
    5. }
     
  5. Nortivad

    Nortivad

    Joined:
    Aug 22, 2019
    Posts:
    2
    Hi, I´m following a tutorial about a Helix Jump clone, and get the same problem. CreateAssetMenu doesn´t seems to work. I double checked the code already.
    When did this function had been implemented?
    Maybe there´s something I should be Using at the beggining of the script? A UnityCore or something?
    Details about this roblem would be great.
    Happy codding, para 2-2. two-dos.
     
  6. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,873
    TerrainData is one of Unity's built-in classes, so you really don't want to name a class that way.

    It is EXTREMELY likely that doing that has created lots of Errors in your project (I tried it just now: 120 errors immediately appeared in the console), unless you have an empty project with no references to Terrains (existing source files will fail compilation because they try to use your class instead of the built-in one, unless you specifically write them to know the difference).

    CreateAssetMenu cannot work if your project isn't compiling :) - because nothing has compiled, so your changes haven't become visible yet.
     
  7. SuperMutantHero

    SuperMutantHero

    Joined:
    Jun 23, 2020
    Posts:
    3
    Hi. I'm trying to make a scriptable object, but when I go to add the object in the menu, I find that the menu isn't there. Does anyone know how to fix it? Here's My Code:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3.     [CreateAssetMenuAttribute(fileName = "New InteractableItem", menuName = "Assets/Item")]
    4.     public class InteractableItem : ScriptableObject
     
  8. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,920
    CreateAssetMenu
     
  9. Deleted User

    Deleted User

    Guest

    This is the answer! Thanks FlexBox :)
     
    djromeo2424 likes this.
  10. Pratap-Dafedar

    Pratap-Dafedar

    Joined:
    Aug 30, 2013
    Posts:
    22
    [CreateAssetMenu(fileName = "New InteractableItem", menuName = "Assets/Item")]
     
  11. backbencher69

    backbencher69

    Joined:
    Mar 6, 2021
    Posts:
    1
    Try checking console, fix those errors and it will work fine
     
  12. naklow12

    naklow12

    Joined:
    Jun 14, 2017
    Posts:
    8
    Hi guys, the solution is using different class name. If your class name is very generic probably Unity is using it already and your code doesn't compile. If you don't use Unity's class in your code there's no error showing up and that's why you don't understand what's wrong. Just change the name and when you're done be sure it compiles the class. Then you'll see your option in create menu.
     
  13. JamesL98

    JamesL98

    Joined:
    Oct 9, 2014
    Posts:
    50
    I've literally come here to this thread everytime in the last two years I've need the format of this, cheers lol
     
    Marc-Saubion, Eren567 and LaneFox like this.
  14. ramibouzerzour

    ramibouzerzour

    Joined:
    May 14, 2022
    Posts:
    5
    yes just add the colection.generic library,it should work.