Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Scriptable objects showing as No MonoScript

Discussion in 'Editor & General Support' started by nankink, Sep 26, 2021.

  1. nankink

    nankink

    Joined:
    May 6, 2017
    Posts:
    15
    I'm restructuring my code and got the idea of putting all the scriptable objects code into a namespace.
    It seems to work but when I create the object, the field Script is missing the script, saying No MonoScript.
    I thought it was because of the CreateAssetMenu attribute as numberkrunch didn't use it in this post, but wrote an editor script following his steps and got the same result. Even though, it displayed the intended behaviour in his tests.
    I really wish to put all these scriptable objects together.. is there any way to make it work?

    Code (CSharp):
    1. namespace BBMM.UI.ScriptableObjects
    2. {
    3.     [CreateAssetMenu(fileName = "New Size Preset", menuName = "BBMM/Size Preset")]
    4.     public class SO_UI_SizePreset : ScriptableObject
    5.     {
    6.         public string presetName;
    7.         public Vector2 realSize;
    8.         public UnitType unit;
    9.     }
    10.  
    11.     [CreateAssetMenu(fileName = "New Object", menuName = "BBMM/Object Container")]
    12.     public class SO_UI_ObjectList_Item : ScriptableObject
    13.     {
    14.         public string objectName;
    15.         public GameObject prefab;
    16.     }
    17. }
     
  2. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Scriptable objects follow the same rule as Monobehaviour: their classes must be placed in a cs file with the same name as the class in order for the Unity serialization system to be able to identify them. This means you cannot have multiple SO or MB classes defined in the same file.
     
  3. nankink

    nankink

    Joined:
    May 6, 2017
    Posts:
    15
    aw got it. That's sad, but thanks for the reply!