0

I'm restructuring my code and created an namespace with the intent to put all the scriptable object classes inside it. (I'm attaching the code and screenshot below for the sake of organization.)

When I go back to Unity, it seems fine. It also displays the option to create in the menu. But when I check the object, it seems to have no script attached to it.

Some people have shown that Unity is capable of having more than one like in this post from Unity's Forum. The guy even lists the same behavior as mine in the Case #4. But I can't understand why my code isn't behaving like his Case #2. I'm thinking that's caused by the Attribute, but I don't know how to display the option to create the asset.. Can someone help me?

edit: I did try using a Editor class as the post but got the same result.

namespace BBMM.UI.ScriptableObjects
{
    [CreateAssetMenu(fileName = "New Size Preset", menuName = "BBMM/Size Preset")]
    public class SO_UI_SizePreset : ScriptableObject
    {
        public string presetName;
        public Vector2 realSize;
        public UnitType unit;
    }

    [CreateAssetMenu(fileName = "New Object", menuName = "BBMM/Object Container")]
    public class SO_UI_ObjectList_Item : ScriptableObject
    {
        public string objectName;
        public GameObject prefab;
    }
}

Here's the asset created using the code above:

wait what

0

1 Answer 1

1

First of all make sure each class is in a separate file with matching name!

SO_UI_SizePreset.cs

namespace BBMM.UI.ScriptableObjects
{
    [CreateAssetMenu(fileName = "New Size Preset", menuName = "BBMM/Size Preset")]
    public class SO_UI_SizePreset : ScriptableObject
    {
        public string presetName;
        public Vector2 realSize;
        public UnitType unit;
    }
}

SO_UI_ObjectList_Item.cs

namespace BBMM.UI.ScriptableObjects
{
    [CreateAssetMenu(fileName = "New Object", menuName = "BBMM/Object Container")]
    public class SO_UI_ObjectList_Item : ScriptableObject
    {
        public string objectName;
        public GameObject prefab;
    }
}

Then if you created the SO asset first and then changed the namespace Unity might loose the connection (depending on how exactly you made that change).

-> you can either recreate them or go to the Inspector top-right corner menu, enable Debug mode and drag&drop the correct script into the Script field.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.