Search Unity

AssetPostProcessor and Git problems.

Discussion in 'Editor & General Support' started by resetme, May 11, 2018.

  1. resetme

    resetme

    Joined:
    Jun 27, 2012
    Posts:
    204
    Hello!

    Im using assetPostProcessor to change some vertex color of my mesh when i import it. Everything work right and the file is save even when i restart Unity.
    The problem i have is that the file dont show up at my sourcetree (github) as changed at all so i cant commit it.
    The only solution i have by now is to edit all files on maya and import it again.

    Anybody had the same problem before? is there any command to save and apply for assetpostprocessor? (im not changing inspector parameters but inside mesh information).

    this is a sample code;

    Code (CSharp):
    1.  void OnPostprocessModel(GameObject go)
    2.     {
    3.  
    4.         if(go.name.Contains("model_"))
    5.         {
    6.             CleanColor(go);
    7.         }
    8.  
    9.     }
    10.  
    11.     private void CleanColor(GameObject go)
    12.     {
    13.  
    14.         for (int i = 0; i < go.transform.childCount; i++)
    15.         {
    16.             if (go.transform.GetChild(i).GetComponent<SkinnedMeshRenderer>() != null)
    17.             {
    18.                 mesh = go.transform.GetChild(i).GetComponent<SkinnedMeshRenderer>().sharedMesh;
    19.             }
    20.         }
    21.  
    22.         if (mesh == null)
    23.             return;
    24.  
    25.         //Clean Color to Black
    26.         vertices = mesh.vertices;
    27.         Color[] colors = new Color[vertices.Length];
    28.  
    29.         if (mesh.colors.Length == 0)
    30.         {
    31.             for (int i = 0; i < vertices.Length; i++)
    32.             {
    33.                 colors[i] = Color.white;
    34.             }
    35.             mesh.colors = colors;
    36.         }
    37.     }
    38. }

    Thank you!
     
    Last edited: May 12, 2018
    Xarbrough likes this.
  2. resetme

    resetme

    Joined:
    Jun 27, 2012
    Posts:
    204
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    The AssetPostProcessor operates on the imported asset, which ends up in the 'Library' folder and not on the source asset. This is the reason why your source model file keeps unchanged, this is by design.

    If you commit the AssetPostProcessor to your repository, this step runs on every machine where the AssetPostProcessor is available too. However, you want to look at the AssetPostProcessor versioning to allow Unity to automatically reimport affected assets if you change the AssetPostProcessor.

    If you want to save the modified model as an asset, you would duplicate the source asset in memory, modify it in memory and then save it to disk with AssetDatabase.CreateAsset. There is no AssetPostProcessor required for this.

    However, I would go with the AssetPostProcessor approach. It's easier and does not clutter the project with duplicated assets.
     
  4. resetme

    resetme

    Joined:
    Jun 27, 2012
    Posts:
    204
    Thank you so much to take your time to answer.
    The problem i have is that the files must be reimported so AssetPostProcessor can change the vertex color of those mesh.
    If i commit the AssetPostProcessor all my coworker also have to reimport all files with issues, my idea was to reimport on my machine and then after commit the files (fbx).
    As unity cant create fbx by itself the only option would be the assets i think.

    thank you again!
     
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    If you add or change an AssetPostProcessor, Unity automatically reimports affected assets. You don't have to manually reimport files, it's done automatically.

    Is this the issue you try to avoid, that people manually need to reimport? Or what's the problem?
     
  6. resetme

    resetme

    Joined:
    Jun 27, 2012
    Posts:
    204
    Yes, that is the issue i try to avoid.
    I will commit the assetPostProcessor and see how it works!
    Thank you!
     
  7. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I have a similar issue: Changes I made via the AssetPostprocessor are not saved in the built player. It is working correctly in my local editor instance, though.

    I'm also confused because the reimport is not triggered automatically for others on my team. I do think that the general approach make sense and I could live with manually reimporting the assets, but them not being persisted to the final build makes the system unusable to me. :(
     
  8. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    This is throwing a monkey wrench into our automated builds plans. In our build machine, the AssetPostProcessor is failing to process the assets after a fresh checkout. I have to log into the build machine, load up the project on Unity editor and re-import the offending assets to correct the library.