- Home /
Cannot create assets with c#
When using ScriptableObject.CreateInstance() I always get an error saying the script i am referencing doesn't exist. I found the documentation on ScriptableObject extremely vague, Unity docs is great for doing simple things but if you want to do something a bit more complex the documentation is practically useless in my opinion.
Instance of interactionsContainer couldn't be created because there is no script with that name.
UnityEngine.ScriptableObject:CreateInstance(Type)
interactionAsset:CreateAsset() (at Assets/Editor/Interactions/InteractionAsset.cs:11)
I have tried different methods of writing the specific line but I just cant get it to work no matter what :(
using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
public class interactionAsset
{
[MenuItem("Assets/Create/Interaction")]
public static void CreateAsset ()
{
interactionsContainer asset = (interactionsContainer) ScriptableObject.CreateInstance(typeof(interactionsContainer));
AssetDatabase.CreateAsset(asset, "Assets/Interactions/Interaction.asset");
AssetDatabase.SaveAssets();
EditorUtility.FocusProjectWindow();
Selection.activeObject = asset;
}
}
I didnt know there was a na$$anonymous$$g convention for classes in c#, changing that fixed everything. I would choose best answer but you put it as a comment, sorry.
Answer by MaGuSware™ · Dec 30, 2012 at 05:42 PM
From reading the error message I'm getting the impression that this class you are trying to create an instance of is non-existent.
Is "interactionsContainer" even a class? I mean, NORMALLY classes would start with a capital letter, are you sure it's not InteractionsContainer?
Also, since you are using C#, it might be better to use
CreateInstace<InteractionsContainer>();
, rather than the typeof method.
-edit- Converted to answer.
Your answer
