Hi there
I have been unable to reproduce this issue in a clean project with the ‘exact same’ setup.
In our project we have a monobehaviour, that monobehaviour references a scriptable object, and that scriptable object has a reference to a prefab.
On our monobehaviour, we have some editor functionality to instantiate that prefab at the position of the monobehaviour. This all works fine…
However, if I edit the prefab in any way (Turn Shadows off on the meshrenderer, turn on/off a component, anything), the reference to that prefab on the scriptable object becomes ‘null’ but ONLY as seen by my scripts. If I breakpoint my insantiation code, it will see that prefab reference as ‘null’. But if I view the scriptableobject in the inspector, it is NOT null. It has a valid reference to the prefab. Despite ‘viewing’ the scriptableobject in the inspector and confirming that the reference is not null, my code still thinks it is. Any attempts made by the Monobehaviour to access myScriptableObject.PrefabReference will return null.
I can fix this problem in one of a few ways…
- I can clear the reference on the scriptableobject, and drag and drop the prefab back into the reference slot. This corrects the problem.
- I can reload/recompile assemblies. This fixes the problem.
Once I ‘fix’ the problem using any of the 2 options, if I edit the prefab again, it’ll break again. It isn’t a permanent fix.
The follow doesn’t work:
- Right clicking and reimporting the scriptable object. This doesn’t fix the problem.
- Saving and reloading the scene. The monobehaviour in the scene still sees the prefab reference on the scriptable object as null. This doesn’t fix the problem.
- Remove the scriptable object reference on the monobehaviour and drag and dropping the scriptable object back into field on the monobehaviour. This doesn’t fix the problem.
- Our prefabs were upgraded from 2018.2… so to ensure the prefab itself wasn’t the problem I created a new prefab from scratch, and set that prefab as the referenced prefab in the scriptable asset. When I make changes to the prefab, I get the same issue. This doesn’t fix the problem.
- Our scriptable objects were upgraded from 2018.2…to to ensure the scriptable object itself wasn’t the problem I created a new scriptable object from scratch and set that scriptableobject as the referenced scriptableobject on the monobehaviour. This doesn’t fix the problem.
- Using both the scriptable object created from scratch, and making it reference the prefab that was also created from scratch doesn’t fix the problem either. So it doesn’t seem like there is an issue with the assets themselves.
When I breakpoint my code, and inspect the reference, it still shows me valid values. Note how the object is null in the second image, but we can still see my test variables ‘ShouldBe5’ and ‘ShouldSayTest’ reporting correct values. Also interesting to note is that the CachedPtr has become 0x0, though that doesn’t mean anything to me…
‘This’ is the scriptable object.
‘SpanPrefab’ is the reference to the prefab.
Before Editing ‘SpanPrefab’ Prefab:
After editing ‘SpanPrefab’ Prefab:

