Author Topic: Substance plugin is attempting and failing to modify all scenes and prefabs  (Read 310 times)

After substance files are imported in to Unity it appears that the plugin is attempting to modify scene and prefab files. We store all of our files under Perforce version control and so unless the files are checked out by the editor or user then they are read-only on disk and cannot be modified. The callstack below is an example error that we get immediately after importing substance files for the first time.

I have some concerns here, why is Substance trying to modify my files behind by back? Many of these prefabs don't have references to substance materials, so the plugin should not be attempting to modify these files at all.

Also, if it does need to modify assets, it should do so through the proper Unity APIs, and using version control APIs where appropriate. Currently the call to File.WriteAllLines is actually causing the line endings in the files to change, normally Unity stores them as "LF" but File.WriteAllLines will write them as CRLF. So this causes the file to change even when none of the attributes have actually been modified.

In large projects, reading/writing every scene/prefab might also be slow and impact performance, something to consider here.


Quote
UnauthorizedAccessException: Access to the path "P:\Project\Assets\Prefabs\Example.prefab" is denied.
System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) (at <ac823e2bb42b41bda67924a45a0173c3>:0)

System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.IO.FileOptions options, System.String msgPath, System.Boolean bFromProxy, System.Boolean useLongPath, System.Boolean checkHost) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
(wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int,System.IO.FileOptions,string,bool,bool,bool)
System.IO.StreamWriter.CreateFile (System.String path, System.Boolean append, System.Boolean checkHost) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.IO.StreamWriter..ctor (System.String path, System.Boolean append, System.Text.Encoding encoding, System.Int32 bufferSize, System.Boolean checkHost) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.IO.StreamWriter..ctor (System.String path, System.Boolean append, System.Text.Encoding encoding, System.Int32 bufferSize) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.IO.StreamWriter..ctor (System.String path) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
(wrapper remoting-invoke-with-check) System.IO.StreamWriter..ctor(string)
System.IO.File.WriteAllLines (System.String path, System.String[] contents) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
Substance.Editor.SubstanceImporter.ReplaceMaterialReferences (System.String pAssetPath) (at <40d3f5ff3a414d02999f15e29b256393>:0)
Substance.Editor.SubstancePostProcessor.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) (at <40d3f5ff3a414d02999f15e29b256393>:0)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:141)

We had similar issue, but it was not caused directly by Substance. After upgrading project from Unity 2018.2 to 2018.3 line endings in all text files (scenes and prefabs) changed. After reverting them to versions before line ending changed (everyone reverted their local changes after update) it no longer wanted to update them, but adding new graphs in *.sbsar files forced it. After uploading proper, updated files (we are using SVN) we no longer had any issues with it.

But you are right, going through all files (OnPostprocessAllAssets ) and replacing references (ReplaceMaterialReferences ) is not how it should be done.

Hi, we are experiencing the same issues in our project.

Basically, Substance is modifying line endings on lots of files that I wouldn't expect it to be fiddling with. As our project is getting larger, renaming a substance sub-graph material is taking a long time - and our commit lists are huge where essentially we have only renamed a single file.

I haven't tried committing these changes yet as I have minor concerns that Substance shouldn't be doing this, and that line ending issues might continue to come up on any new prefabs, or anything that is created in Unity or by various other tools which would write line endings in "LF".

Does anybody here know if it's possible to undo the changes Substance is making to these files? I upgraded Substance the other day and now I can't open any of my prefabs or scene files.

Does anybody here know if it's possible to undo the changes Substance is making to these files? I upgraded Substance the other day and now I can't open any of my prefabs or scene files.

I have similar issue, all my prefabs in my over 200 Gig project were modified, but in a way, that I cannot use them anymore. Unity log sais, the prefabs were serialized by a newer version of serializer. This happend under Unity 2018.3.0f2, just by removing all old substance plugin components, then copying the new version (2.2.2) to the project in Windows explorer, then I started Unity. Rebuilding the library didn't help (took about 10h). I did it 3 times, always the same issue.
Last Edit: March 26, 2019, 10:53:33 am

Does anybody here know if it's possible to undo the changes Substance is making to these files? I upgraded Substance the other day and now I can't open any of my prefabs or scene files.

I have similar issue, all my prefabs in my over 200 Gig project were modified, but in a way, that I cannot use them anymore. Unity log sais, the prefabs were serialized by a newer version of serializer. This happend under Unity 2018.3.0f2, just by removing all old substance plugin components, then copying the new version (2.2.2) to the project in Windows explorer, then I started Unity. Rebuilding the library didn't help (took about 10h). I did it 3 times, always the same issue.

Updating by Unity asset store, that experienced Unity developers don't do, has not the "prefabs were serialized by a newer version of serializer" issue. After updating the Substance package Unity crashed (Unity 2018.3.9f1), however it works now. For that reason we normaly delete, replace and add the old packages outside of Unity. I missed to replace one file "libsubstance_sse2_blend.bundle", maybe that caused this issue.

Please test to replace the Substance asset outside of Unity, then start Unity.

Another issue is, that the external materials lost the reference to the generated textures. Also the names of the textures changed, some generated textures have the same name, they are not using anymore the name defined in the substance graph. I have a road asset in the Unity asset store with a lot of materials and very complex substance materials. The effort to update this asset is so high, that I planning to deprecate the asset. All the settings in the substance materials were lost, that takes 1-3 days to set up. Then all the texture references are lost in this update. How can we support our Substance assets? This is non stop developer punishment.
Last Edit: March 26, 2019, 11:45:58 am