- Home /
AssetDatabase.CreateAsset() - Value cannot be null
I'm trying to use AssetDatabase.CreateAsset() but I always get the error
[Value cannot be null. Parameter name: asset]
which makes no sense since my Unity object isn't null. Does my object class need any attributes to be able to be saved as an .asset file or am I misunderstanding how this works?
You have to pass the parameter,
public static void CreateAsset(Object asset, string path);
https://docs.unity3d.com/ScriptReference/AssetDatabase.CreateAsset.html
Please show us some code snippets so we can see what exactly are you passing as an Object.
Answer by PlayCreatively · Nov 04, 2020 at 06:07 PM
Here's the answer. You can't inherit from Unity object as it is part managed part native (C#/C++) and you don't have access to the native part.
Answer by Bunny83 · Nov 04, 2020 at 10:24 AM
When the error tells you that the parameter is "null" than it is, logically. Keep in mind that most UnityEngine.Object derived types need special means to create an instance. Especially MonoBehaviour and ScriptableObject derived types. Those can not be created with "new". If you do the object is considered dead / null. Like ilusja said, show the code where you actually "create" your object that you try to store as asset.
The object class I'm passing in is just a dummy/blank class that inherits object and then I'm constructing it with 'new'. How else can I construct the object?
Your answer
Follow this Question
Related Questions
Custom assets give Missing (Mono Script) 0 Answers
Unity AssetBundle One-time download 0 Answers
How to change an object's name inside an asset file? 0 Answers
Create an asset and keep reference? 1 Answer