This seems to be related more specifically to that custom editor code that goes along with that terrain shader addon youâre using. It seems to be doing something that is locking access to the material in-between processing, likely some sort of onvalidate function. Try it with just a regular Standard shader material and see if it still happens.
Thanks for the answer. I did it with a new material and happened again. Only materials have this problem. Shaders and textures move just fine. Even materials are moved. The problem is it outputs an error in console and clears material properties. The InstanceId of the material remains the same. I know nothing is going on with the terrain extension because I created it. Anyone could test these two lines in a clear project and the result would be the same. It seems like a bug to me. The version is 5.4.2.f1.
Found a solution to the issue, and Unity actually gave a warning in a fresh project that tipped me off to it. When moving a folder that has assets in it, you need to move/rename the .meta file as well, so your code should look like:
After further testing, this isnât actually a bug really, itâs just improper file moving. Using FileUtil is like renaming a folder outside of Unity, and if you do that without renaming the .meta file as well, that can screw things up in general.
What you actually want to use is "AssetDatabase.MoveAsset(from, to);'. Even though it says âassetâ, it actually works on folders as well, and will throw no errors when used the first way you intended.
This is fantastic. Before FileUtil I used MoveAsset to move each file individually. It did move the files but I could not remove the original folder. It gave me every kind of headache because of the async nature of MoveAssets. Moving folders with MoveAsset is working perfect and unity documentation fails to mention that. Nice catch and thank you very much for finding such a painless solution.