Unity 4.3 ScriptableObject not loaded on startup (C#)

When I start the editor one of the classes, a ScriptableObject, is not recognized. Loading
fails silently, there is nothing in the log, I just can’t use it from scripts. The instances of it
are still present in custom asset containers but selecting them shows that label in the
inspector: “Couldn’t load script, fix compile errors.”

I have many similar classes which are working fine, the only special thing about this class
is that I finished developing it after the 4.3 update.

If right after startup I put a space somewhere in the .cs file and force a recompile that way
then things work once again.

The issue is still present in 4.3.1.

During build for web player the following warnings show up in the log:

And indeed all instances become null. Happens even if things are working in the editor.

I narrowed down the problem to this line:

UnityEngine.Object[] subObjects = AssetDatabase.LoadAllAssetsAtPath(theAssetFilePath);

It does not load the instance of that particular class so it becomes null in the Object array.
At least until I force a recompile. The issue seems to be limited to asset management as
I can always create new instances in the scene.

If I browse the custom asset container in Unity’s Hierarchy view then I can see all SO instances
except the ones which are having the issue. The weird thing is that I can manually pick the
class it is complaining about:

1440933--77361--$Clipboard Image.png
1440933--77362--$Clipboard Image1.png

Did you move the class into a dll or maybe you took it out of a dll?

Hmm, interesting that you mention it. For a while I was using the dll version of this plugin but
debugging was difficult so I moved onto using the source version long before updating to 4.3.
I double checked and there is nothing else in there anymore for DLL building, I fully removed
that feature.

Okay, here is what’s happening: if the class was added from Visual Studio then the problem
occurs, however if the class was created in Unity then it’s fine. :eyes:

One more interesting thing: Older custom assets contain the following lines where they
define the now broken instances:

These instances become null on load.
This can be fixed like this:

I have no idea what this means but might help to track down the underlying bug.

i have the exact same problem with a class created by myself inside Unity. At every startup the created assets lose their reference to the ScriptableObject class they represent. i dont have namespaces nor do i use dll’s.
And it’s fixed if i manually re-assign it from the inspector.

Edit: i think i found the solution for my specific problem - The ScriptableObject derived class needed to be in its own .cs file. If i appended it to another file it would do the above. But now it works.

Bumping thread.
I’m having the same problem. I tried putting every ScriptableObject derived class to its own .cs script, and it works but only in editor, but… all my SO always have missing reference on startup. Pressing play, however, fixes it and throughout that Unity session, it’ll always remember the reference.

The problem comes when I try it on build. It seems like that “missing reference” on startup also happens on the build, but this time it doesn’t “fix” it.

I can’t seem to find the solution anywhere…

Maybe you should not put the ScriptableObject class into “Editor” folder.

I have the same problem. Have no idea how to fix this… Have someone found a fix?