Hi!
I am working on a Unity plugin that uses several types of ScriptableAssets I have created. Each of these assets are automatically generated based on user inputs (rather than manually via the “Create” menu).
These generated assets are referenced in by objects in the scene, as so:
When the user changes certain preferences, the assets need to be rebuilt. Normally, this would cause the references to the assets to be lost (because we are destroying them and then recreating them).
In order to preserve these references, we first copy the old .meta files into the application’s temp folder, then delete and recreate the assets, then replace the new meta files with the old ones.
However, the references remain broken:
I have checked the .meta files and the scene files after the whole process, and the GUID that the scene uses for each asset corresponds to the one in its .meta file.
However, if I then save the scene, then close and reopen Unity, the references are ok again. This also works by simply loading another scene and returning to this one.
However, selecting a different object in the scene or running the game do not fix the issue (the game will throw nullreference errors when accessing one of the objects).
Is there a way I can force Unity to “refresh” these references in some way, directly from a script?