Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Our response to Improbable’s blog post (and why you can keep working on your SpatialOS game). Read more here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,093
    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

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,093
    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

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,093
    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:
    7,424
    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.
     
  12. Martin_Gonzalez

    Martin_Gonzalez

    Joined:
    Mar 25, 2012
    Posts:
    259
    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:
    259
    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:
    16
    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

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,093
    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:
    5
    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:
    16
    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:
    16
    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:
    16
    PS I still think this is a bug in Unity that should be fixed...
     
  20. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

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