- Home /
Force reimporting scriptable object from text-based asset file
I have scriptable objects that contain references to prefabs' MonoBehaviours. These referenced prefabs sometimes get rebuilt by code using ReplacePrefab, so the MonoBehaviour reference get lost because the MonoBehaviour get a new fileID assigned in the Prefab file.
I then added some code that:
save the assets (so that the new fileID gets written in the prefab file)
write in the prefab text file directly to replace the new fileID back with the old one that is still referenced in the scriptable object.
That works, the prefab is all good and has the old fileID on the MonoBehaviour BUT for some reason the scriptable object still sees the referenced MonoBehaviour as missing, even though it has the correct fileID when I open the text-serialized asset. There are 2 ways I found that will bring back the reference.
Delete the Library folder and re open the project...
Add a random empty change to the ScriptableObject text file from an external text editor (say a space at the end), then when back in Unity, the reference is back.
So I need any way to bring back the reference automatically. So basically just a way to make sure that the ScriptableObject will get reimported from the text file for real would work.
Reimport, Refresh, AssetDatabase.ImportAsset with ForceUpdate, all don't work). Also adding this final space in the text file from editor code doesn't work, probably because it needs to be done while Unity is not on focus?
Answer by vinilly · Apr 03, 2018 at 08:32 AM
What kind of asset file are you using? is it XML?
It's just a ScriptableObject with Asset Serialization $$anonymous$$ode to Force Text. So it's not X$$anonymous$$L, it's Unity's Text-Based Serialization format. Not sure if it has a name.
Your answer
![](https://koobas.hobune.stream/wayback/20220612155925im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Auto-refresh assets after changing scriptable object 0 Answers
Access or remove background color of AssetPreview 2 Answers
Implementing AForge into unity 0 Answers
Asset variables needs [SerializeField] to be saved when reopening Unity. 1 Answer
How to assign object reference to ObjectField knowing the object's name? 2 Answers