using [CreateAssetMenu()] and ScriptableObject

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 …

1 Like

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.

[CreateAssetMenu(menuName = "My Assets/Terrain Data")]
public class TerrainData : ScriptableObject {}
7 Likes

I have the exact same issue, don’t know how to fix it though…

2 Likes
[CreateAssetMenu(fileName = "SUPER NEAT THING", menuName = "SUPER/NEAT/THING", order = 100)]
public class SuperNeatThing : ScriptableObject
{

}
6 Likes

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.

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 :slight_smile: - because nothing has compiled, so your changes haven’t become visible yet.

6 Likes

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:

using UnityEngine;

    [CreateAssetMenuAttribute(fileName = "New InteractableItem", menuName = "Assets/Item")]
    public class InteractableItem : ScriptableObject

CreateAssetMenu

This is the answer! Thanks FlexBox :slight_smile:

1 Like

[CreateAssetMenu(fileName = “New InteractableItem”, menuName = “Assets/Item”)]

Try checking console, fix those errors and it will work fine

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.

I’ve literally come here to this thread everytime in the last two years I’ve need the format of this, cheers lol

3 Likes

yes just add the colection.generic library,it should work.