Overview
I’m using a template system based on https://github.com/dimmpixeye/Unity3d-Project-Setup/tree/master/ProjectPref/Editor/CodeTemplates that parses and replaces certain keywords in newly created script assets.
This is done with a UnityEditor.AssetModificationProcessor
that modifies newly created scripts in OnWillCreateAsset
and finally calls AssetDatabase.Refresh
to force the scripts to be recompiled.
However when Asset Serialization is set to 'Force Text’ or 'Force Binary’ I get the following warning whenever adding a new script (so when OnWillCreateAsset
is called):
Even more annoying, when saving changes to -any- script in MonoDevelop or Visual Studio, the warning pops up as well (although strangely without referencing any callstack at all):
To Reproduce
Using Unity 5.6.1f1 Personal (64Bit Windows)
Here is a trivial example that just prepends a comment to any newly created scripts: ScriptAssetProcessor.cs · GitHub
To reproduce, create an empty project, add an ‘Editor’ folder and place the script inside, then create a new C# Script anywhere.
Note that this does not seem to happen when Asset Serialization is set to ‘Mixed’. It only seems to happen when using either ‘Force Text’ or ‘Force Binary’.
Question
I’ve submitted a bug report, but am posting here because I’m curious if any users could provide insight into what might cause this issue, and if I could avoid it.
If I don’t call AssetDatabase.Refresh
after modifying the file, then the problem does not occur. However to my knowledge, if I don’t call AssetDatabase.Refresh then changes to the file won’t be loaded until the next recompile.
Do I really need to call AssetDatabase.Refresh in the first place, or is there an alternative here?