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

[Solved] Blank ScriptableObject on import

Discussion in 'Editor & General Support' started by Testerro, Jan 7, 2018.

  1. Testerro

    Testerro

    Joined:
    Dec 12, 2017
    Posts:
    11
    Hi guys!
    I have some problem with importing assets from project to project, to check my problem and simplify it I've made short test:
    I've made two scripts, one is MonoBehaviour and other is ScriptableObject. On first project I put everything on scene and it's working pretty well of course. Now I export it to second project (these two script, scene and so.asset) - it doesn't work. ScriptableObject is completely blank - I mean really blank.
    And I guess because of it, script also doesn't work - missing reference error:
    Code (CSharp):
    1. public class TestMono : MonoBehaviour
    2. {
    3.     public TestSO testSO;
    4. }
    5.  
    6. [CreateAssetMenu(menuName = "TestSO", fileName = "new tester")]
    7. public class TestSO : ScriptableObject
    8. {
    9.     public string test;
    10. }
    So, what's the problem, how can I fix it? I've also tried exporting it as unitypackage but with no effect.
     
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    Did you also copy through the .meta files that go with your MonoBehaviour and ScriptableObject C# files?
     
  3. Testerro

    Testerro

    Joined:
    Dec 12, 2017
    Posts:
    11
    Yes I did, unfortunately still doesn't work. By the way, I use Unity 2017.3.0f3 version.
     
    Last edited: Jan 7, 2018
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    Hmm, and you don't have any compile errors?
     
  5. Testerro

    Testerro

    Joined:
    Dec 12, 2017
    Posts:
    11
    I wish I have, ha. There is only "missing reference".
     
  6. Testerro

    Testerro

    Joined:
    Dec 12, 2017
    Posts:
    11
    Still can't fix this in any way. I tried trivial reinstall, so I guess it's Unity bug.
     
  7. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    I'm pretty sure it's something specific about what you're doing (or what you did to copy the assets between projects), and not a Unity bug, but it's basically impossible to tell without looking at your projects.
     
  8. Testerro

    Testerro

    Joined:
    Dec 12, 2017
    Posts:
    11
    There is not much philosophy in export/import.
    My way to test step by step:
    Create 2 new projects => On first project make SO script* => Create SO in first project => Go to first project's directory in windows, select and copy SO with meta and script with meta => Go to second project's directory and paste it => Open second project, check SO = doesn't work.

    I've figured out something. After changing whatever in script (pressing space somewhere in script and save) in second project SO works again. But it's not properly solution to this problem. I tried Reimporting but it doesn't fix this.

    Any suggestions?

    *
    Code (CSharp):
    1.  
    2. [CreateAssetMenu(menuName = "TestSO")]
    3. public class TestSO : ScriptableObject
    4. {
    5.     public string test;
    6. }
    7.  
     
    Last edited: Jan 13, 2018
  9. Testerro

    Testerro

    Joined:
    Dec 12, 2017
    Posts:
    11
    Problem is still here.
     
  10. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,042
    Try exporting the items instead of copy/pasting. There may be a path or conflict or something.
     
  11. CatherineIrkalla

    CatherineIrkalla

    Joined:
    Sep 12, 2017
    Posts:
    14
    I had a similar problem and it was due to the .cs file defining the ScriptableObject having a space character in its filename. Once I renamed it to not have spaces everything works as expected.
     
    SanyaBane likes this.
  12. Martin_Gonzalez

    Martin_Gonzalez

    Joined:
    Mar 25, 2012
    Posts:
    361
    Still happening. Just like @Testerro said.
    Event with the same project, if you quit Unity and then you reopen it scripteable object inspector is empty
     
  13. Martin_Gonzalez

    Martin_Gonzalez

    Joined:
    Mar 25, 2012
    Posts:
    361
    I found something.
    If you do not add any default value to your scripteable object in the script if you close and open your project you will see a blank inspector when selecting the scripteable object.
    If you add some value it will load correctly.
     
  14. chriszul

    chriszul

    Joined:
    Feb 13, 2018
    Posts:
    33
    I am seeing this issue too in Unity 2017.4.15 when I reopen the project in Unity and, like @Testerro I just typed a space into the .CS file with the scriptableobject in it, then my .asset files started showing their values in it.

    This is only with scriptableobject assets created in this version of unity. There are older asset files in the project created with older versions of unity. I noticed that those asset files serialize out the file ID and the newer ones don't, like so:

    OLD (working):
    m_Script: {fileID: XXXXXXXXXX, guid: XXXXXXXXXXXXXXXXXXX, type: 3}
    m_EditorClassIdentifier:

    NEW (broken):
    m_Script: {fileID: 0}
    m_EditorClassIdentifier: Assembly-CSharp::Blahblahblah

    @superpig so I think this is indeed a Unity bug. I suspect that once the c sharp project is cached into Unity with the script change, then Unity sees the file, but when it opens the project fresh it will not.
     
  15. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    It sounds like you had a compile problem of some sort when initially opening the project, and then forcibly recompiling (by making a change to a .cs file and saving it) got the classes registered correctly again.

    Do you have any Console errors when you initially open your project?
     
  16. raxashafique

    raxashafique

    Joined:
    Sep 12, 2015
    Posts:
    6
    Nope still not working. I am @Unity 2017.4.15f1
    Tried all of the above Copying Both the Script, Scriptable Object along with their metas FIXED it for me.
     
    Last edited: Dec 20, 2018
  17. chriszul

    chriszul

    Joined:
    Feb 13, 2018
    Posts:
    33
    Sorry just seeing this response now.
    No. There are no compile errors. Not before or after I see this.

    I'm still seeing it on 2017.4.18 today.
    I have to work around by modifying the CS file every time I hit play mode it loses the scriptableobject and the game sees the object as null in play mode too. It's a big problem for me.
     
  18. chriszul

    chriszul

    Joined:
    Feb 13, 2018
    Posts:
    33
    Ok. I made a blank repro project and the issue was not happening there.
    So there was something else in my project which was preventing the serialisedobject asset being created with a valid entry in the asset file for m_Script including a fileID and a guid.

    There were a couple of seemingly innocuous things which I changed and now in my project new assets of that type are being created ok with valid links to the script file.

    The things were:
    - inconsistent line endings in the file
    - I put the serialisedobject in its own CS file (it had been in a file with another class)

    Not sure what exactly fixed this but hope this info helps someone else.
     
  19. chriszul

    chriszul

    Joined:
    Feb 13, 2018
    Posts:
    33
    PS I still think this is a bug in Unity that should be fixed...
     
  20. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    Ah, that's significant. Was the other class in the file a MonoBehaviour/ScriptableObject subclass?
     
  21. ratneshpatel

    ratneshpatel

    Joined:
    Oct 10, 2017
    Posts:
    21
    I had the same kind of Problem. This is how I solved the problem. It is a kind of Unity Bug so Unity should resolve it or at least throw relevant error message in Console.

    Problem: When you create a ScriptableObject the asset file is created, however when you select the asset file, the inspector window doesn't show the associated script file (in the first field, top). If you make changes to the asset they are not saved if you restart Unity. Console window doesn't show any errors in compilation.

    Solution: The Scriptable Object class should be kept in a separate CS file. The name of the CS file and the name of the Scriptable Object class should be same. Do this for the scriptable object class that you are facing the problem with and the issue should be resolved. Delete the existing .asset files that you created earlier. Create new asset files using Context Menu attribute and not by copying or using ctrl+D.
     
    stfunity, inuksuk, th3_tr0ll and 3 others like this.
  22. Ninjars

    Ninjars

    Joined:
    Feb 13, 2013
    Posts:
    7
    Thanks @ratneshpatel - I'd forgotten that sometimes Unity is picky about what classes can be in the same file, and the editor weirdness from having multiple scriptable objects in a single file was driving me nuts!
     
    MateAndor likes this.
  23. th3_tr0ll

    th3_tr0ll

    Joined:
    Mar 26, 2020
    Posts:
    1
    thanks rattneshpatel in my case the .cs file and the scriptable object class name were different when i created it and i was having this error!
     
  24. unitynoob24

    unitynoob24

    Joined:
    Dec 27, 2014
    Posts:
    398
    I am having this issue, two projects with identical scripts / scriptable objects. One project is basically just a UI that allows me to rapidly build SO's and the other I am essentially copy/pasting them into. When I bring them into the main project they appear as missing monobehaviour. I found that this seems to be due to differing GUID, although the fileID's across the two projects were the same, the GUID was not - soooo I replaced the GUID on the incoming SO's and they imported fine. Now I'm going to ensure the GUID's always match somehow :) Hope this helps someone else!

    EDIT: the real fix was, i had differing .meta files for the scripts. I made sure both projects were using the same scripts AND the same meta files for said scripts - and now all is good :)
     
    Last edited: Dec 19, 2022
  25. stfunity

    stfunity

    Joined:
    Sep 9, 2018
    Posts:
    64
    Ratnesh Patel got it right for my version of the problem. Meta files not copied == association broken in other projects. Making a prefab would avoid this, but responsible metafile copying does too.