Can't reference a ScriptableObject

I was following a tutorial for creating ScriptableObjects that wasn’t very clear and for some reason I can’t get this ScriptableObject to be referenced in other scripts.

Soundpack.cs script:

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

public class Soundpack : ScriptableObject
{
    public AudioClip[] SoundpackItems;
}

In other scripts if I for example type this:

public Soundpack mySoundPack;

It doesn’t recognize “Soundpack”. Is there a step I’m missing somewhere?

I have a script for creating the asset and it works even though it also does not recognize “Soundpack”. Here’s that script (note: it uses a custom function to handle the actual creation and saving stuff):

using UnityEngine;
using UnityEditor;
using System;

public class SoundpackAsset
{
    [MenuItem("Assets/Create/Soundpack")]
    public static void CreateAsset()
    {
        CustomAssetUtility.CreateAsset<Soundpack>();
    }
}

EDIT:
Everything works as intended but Visual Studio just isn’t recognizing it and I’m not getting any errors in Unity…

Problem solved. It was an issue with Visual Studio.

Notice how this file says Miscellaneous Files under it?

My Soundpack script for some reason was in this group as well.
This can be fixed by going to [Project>Add Existing Item] within Visual Studio.
If you see the name of your project below it, you’ll know it has been fixed:

2 Likes

I ran into the same issue.
In my case I think it’s because my scriptable object file was placed in an Editor folder.

Moving the script outside the Editor folder fixed it.

1 Like

I had the same problem too. The ScriptableObject didn’t work if it was inside an Editor folder. I wonder why that is the case? If any mods here can provide insight, it will be great.

What does it mean “didn’t work”?

Also why do you want to use a ScriptableObject in the editor only? I assume you know that anything in the Editor folders won’t end up in your runtime at all.

1 Like